One of the parameters of the position function enables you to specify whether you are looking for the 1st, 2nd... instance of the text. Another parameter specifies the starting position of your search of the text field.
So in a looping script, can either search for the next instance of particular text by setting the start value to a value just to the right of the last instance found or you can increment the other parameter to specify the "instance".
Position returns zero when no text is found so you can stop when it returns zero.
A recursive custom function could also be constructed to do this kind of loop.
I suggest looking up this function in FileMaker help to learn the details.
it looks like you're using a custom function ParseBetween.
The one I saw online was only designed to find the first occurrence. So you'd need a different custom (recursive) function (or a function script with a loop) to extract multiple instances of the item number.
beverly, what is JSON?
philmodjunk - I've spent the better part of 3 weeks jumping from one calculation/function to the next in FM help. Though I'm getting better at manipulating text by identifying patterns and making the variable text more predictable, I'm still having difficulty grasping how to apply looping scripts, Let calculations and what I believe are (for me) more complex, recursive (?) functions. The examples provided are either so simple relying on consistent, non variable / fixed length / fixed pattern records, or they seem so abstract that I'm unable to make the leap on how to apply it to what I'm trying to do.
JSON is a format commonly used in web feeds, along with XML, these are TEXT formats that can be parsed for usage once data is exchanged.
The links I provided will help parse that particular kind of text format.
Another problem I face deals with a limitation for recursive functions. I'm using _FilterXML, one of briandunning's custom function to strip invisible ascii text that has been wreaking havoc with my parsing. It works great, but I've learned that if the record's length is greater than 10,000, then the function doesn't work. So, any solution I work out will need to handle the large record length.
Thanks beverly. Though I've made reference to using _FilterXML, I'm not parsing text from web feeds. I'm parsing data I've pasted primarily from PDFs and certain news articles online. I'm trying hard to stay away from learning other languages if there's an option available in FM. Is it still your recommendation that the JSON solutions will be a better solution to what I'm trying to accomplish?
JSON is just another format. If your text is XML, use the XML parsing. If your text is JSON, use the JSON parsing. If it's neither, then the built-in functions and custom functions and possibly the plug-ins can be used.
If your current custom function does not account for multiple instances of text, then it can be revised.
I tend to do a
PatternCount ( )
test before I do most parsing then I have the "pattern" and how many times it occurs. I may use a Loop on each pattern and the Position()
function does take an "occurrence" parameter. So with the loop and the number of occurrences, you can apply other parsing to each section where the pattern occurs.
your PatternCount suggestion makes sense to me. I've already identified the number of occurrences and the positions of the first and second occurrences.
Before I try looping (which I've not yet done before), I'd like to try to understand what I will be looping first
I am using the ParseBetween calculation, because xxxxx represents a variable length sequence of. But, I know the starting point is "ITEM" and I know the ending point is a ¶.
I have several records that have 2 occurrences of "ITEM xxxxx". I want to parse the second occurrence of "ITEM xxxxx¶" into a field. I know the position of the first occurrence is 663 and the second occurrence is 884.
I tried the following, but it didn't work:
ParseBetween ( recordtext ; Position ( recordtext ; "ITEM" ; 0 ; 2 ) ; ¶ )
Would you please let me know what I missed?
David, you are a gem... let me see if I'm able to apply it.
Yeah, that's where the comments would have been helpful.
The Set Field $text, inside the loop, lops off the left portion of the original text up to the beginning of the item number, including the $key. So the beginning of the value is now the leftmost part of $text. That way, you don't need to keep track of multiple start positions.
BTW, there is no error catching - $endOfValueChar must always exist after the value. And $endOfValueChar should really be called $endOfValueString. And the variable $item should be called $value. And I wasn't OC consistent with my syntax.
you are a treasure, David!!
I don't understand line 15... the script seemed to work without it, but I'd like to know what your intent was. But, I was able to get it to work!
Your lack of comments was perfect because you helped turned an abstract concept into a concrete example for me - which worked wonders for my understanding.
Instead of the custom dialogue, I set a destination field for the list results. I changed the GetAsNumber to GetAsText, since my particular needs are for a text result.
I look forward to applying this to MANY other things on which I'm working. Thank you.