Forum Discussion

JonathanHeuer's avatar
JonathanHeuer
Qrew Cadet
4 years ago

Find position of text string in larger string

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
------------------------------

10 Replies

  • 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
    ------------------------------
    • JonathanHeuer's avatar
      JonathanHeuer
      Qrew Cadet
      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
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        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
        ------------------------------
  • 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
    ------------------------------
    • JonathanHeuer's avatar
      JonathanHeuer
      Qrew Cadet
      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
      ------------------------------
      • NeilSchneider's avatar
        NeilSchneider
        Qrew Cadet
        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
        ------------------------------