# Discussions

View Only

## Find position of text string in larger string

• #### 1.  Find position of text string in larger string

Posted 12 days ago
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 12 days ago

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
http://QuickBaseCoach.com
mark.shnier@gmail.com
------------------------------

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

Posted 12 days ago
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 12 days ago
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
http://QuickBaseCoach.com
mark.shnier@gmail.com
------------------------------

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

Posted 12 days ago
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 12 days ago
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 11 days ago
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 11 days ago
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 11 days ago
..Jonathan,  was there a problem with using my solution an an approach?

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

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

Posted 11 days ago
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 11 days ago
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