Is there anyway I can substitute only the first occurence of a text?
FileMaker Pro 16 Help
Has the advantage of a 'start' and 'numberOfCharacters'.
If you need these values, then Position() & Length() would give you that information.
Has the 'occurence', so meets OPs "first" requirement
Yes, but not using substitute alone.
Please provide an example of what you need.
Here is what I need:
Let's say I want to substitute the word fruit with apple, orange, banana in the following text:
I like eating fruit. Fruit is tasty. I ate the whole fruit.
After replacement it will look like:
I like eating apple. Orange is tasty. I ate the whole banana.
By replacing first occurrence, I can replace the first fruit with apple. In the second run I can replace the second fruit with Orange and so on.
Take a look at the position and other text functions. Position can locate the first instance of your text so that you can then use other functoons such as length, middle, left, right to do the substitution.
in this case you probably wouldn't even touch the Substitute ( ) function, which would substitute all instances of "fruit". The function you're looking for here is Replace ( ) in combination with, as philmodjunk suggests, Position ( ), Middle ( ), and other text functions.
Interesting. I hadn't even considered Replace and that just shows that there's more than one way to do this.
My thoughts ran thus.....
After using Position and length to get the needed character positions and string lengths:
Text to the left of the text to be replaced & Replacement Text Here & Text to the right of the text to be replaced.
Left or middle gets you the first sub string. Right or Middle gets you the last substring. The middle substring is, of course, specified in a field, variable or script parameter.
I tried to play around this (without Position()), but your example (Orange) is not only "substitute only the first", it need case insensitive on search and keep capital in source.
Thank you everyone. I used Position, Length and Replace to solve this problem.
Wonderful! You might mark an answer as correct (even your own). Or mark the question as assumed answered. That way others may know what worked!
The problem with mark an answer as correct is that there's multiple correct answers. I wish there's a way to select multiple correct answers.
Click "assumed answered" (overall) and "helpful" on the multiple 'correct answers'.
Retrieving data ...