Discussions

 View Only
Expand all | Collapse all

Find position of text string in larger string

  • 1.  Find position of text string in larger string

    Posted 09-15-2020 23:09
    I have a long string in my Services table, the result of a Combined Text Summary field, each element takes the pattern V###-#### (where the number parts of the string are arbitrary length). For example :
    V102-136 ; V23-4072 ; V8-25
    I want to create a formula which extracts correct element in this array, based on the value in another field, and I could do it if I knew the position in the text string of the "V" value. So if there were a function Find which returned the position of a text string, that would do it. Something like
    Find([Summary Field", "V" & [Text string to search for])
    I can't find a function to do this. Functions like left just search for single characters, and I need to search for a longer string. Ideas?

    ------------------------------
    Jonathan Heuer
    ------------------------------


  • 2.  RE: Find position of text string in larger string

    Posted 09-16-2020 08:56

    I would approach this differently. I would use the part function in QuickBase to isolate the different elements and then use a case function to determine the result.

    var text value = totext([my multi select field]);

    var text A = Trim(Part($value,1,";"));
    var text B =Trim(Part($value,2,";"));
    var text C = Trim(Part($value,3,";"));
    etc
    var text Z = Trim(Part($value,26,";"));


    Case([value in another field]),
    1, "$A,
    2, $B,
    3, $C,
    etc

    26, $Z)



    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------



  • 3.  RE: Find position of text string in larger string

    Posted 09-16-2020 10:57
    Thanks Mark, I like this approach. The problem is that the length of the array in the summary text field is arbitrarily long; that is, it may well have more than 26 elements in it.

    ------------------------------
    Jonathan Heuer
    ------------------------------



  • 4.  RE: Find position of text string in larger string

    Posted 09-16-2020 11:11
    Well there is no limit to the length of a formula 


    var text AA = Trim(Part($value,27,";"));
    var text AB =Trim(Part($value,28,";"));
    var text AC = Trim(Part($value,29,";"));
    etc.

    just make the formula longer, for the largest number of practical elements, say 100?  Whatever,  it's just copy and paste to make the formula longer.




    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------



  • 5.  RE: Find position of text string in larger string

    Posted 09-16-2020 10:53
    If you only want to know if the summary field contains the value you are looking for (and don't need the index in the array), this should do it..
    var text data = "V102-136 ; V23-4072 ; V8-25";
    var textList dataList = Split($data, ";");
    var text field = "V23-4072";
    var bool hasField = Contains($dataList, $field);

    If ($hasField, $field, "notfound")

    ------------------------------
    Neil Schneider
    ------------------------------



  • 6.  RE: Find position of text string in larger string

    Posted 09-16-2020 10:58
    Thanks Neil- yep I know about Contains. The problem is I need to extract the actual value from the text string, not just whether it's there or not.

    ------------------------------
    Jonathan Heuer
    ------------------------------



  • 7.  RE: Find position of text string in larger string

    Posted 09-16-2020 14:27
    Jonathan,
    I probably misunderstood the question.  The formula field would return the actual value if the value is found in the string. The example returns "V23-4072", did you need the index of the value?

    ------------------------------
    Neil Schneider
    ------------------------------



  • 8.  RE: Find position of text string in larger string

    Posted 09-16-2020 15:14
    Neil I'm sure I didn't clearly explain. Once I search for "V23" and obtain it's position, I'll ultimately want to get the value after the hyphen, "4072". But if I can find "V23" in the larger string, I'm fairly confident that I can extract the part after the hyphen.

    ------------------------------
    Jonathan Heuer
    ------------------------------



  • 9.  RE: Find position of text string in larger string

    Posted 09-16-2020 15:37
    ..Jonathan,  was there a problem with using my solution an an approach?

    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------



  • 10.  RE: Find position of text string in larger string

    Posted 09-16-2020 15:45
    I haven't implemented it yet, but I think it would work fine. I was just hoping to find a solution which didn't limit the size of the array. Right now there are <10, but it could grow by quite a bit.

    ------------------------------
    Jonathan Heuer
    ------------------------------



  • 11.  RE: Find position of text string in larger string

    Posted 09-16-2020 15:47
    Right, I think that you will find that using the formula language in the formula field boxes, you will not be able to generate an array.

    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------