find position of last space in a text field
How can I find the last occurrence of a space (" ") in a text field? Apparently " " is not a valid 'searchstring' in the 'position' function.
It should be.
Position ( TextField ; " " ; Length ( textField ) ; - 1 )
should do the trick. It works for me when I test the above in Windows 7, Filemaker 13 Advanced...
@Phil. Just curious (aren't I always). Without knowing the full details of why the OP needs this, would (should) someone also account for a previous user who might hit an extra return or hit the space bar a couple of times at the end of the text field before leaving the field? Could (should) you first Trim the field, (or have it trim in Auto Enter)
I'd certainly consider something like:
Trim (Self ) as a way to remove unwanted trailing and leading spaces from such a field. Didn't mention it only because it wasn't what Tom Pingel asked for. It's good point though and a reasonable guess as to why he posted this question.
The other thing that can create the appearance that such a function is not working is that you can have characters that look like spaces but are actually other nonprinting characters such as tabs, returns, non-breaking spaces...
It's not a 'trimming' issue. And the issue is using a space (" ") as the search string in the position function.
When I start at the end of the string and back up a character at a time checking to see if it equals " ", I can find the last space (using the 'middle' text function).
But using the position function to find a " " character fails.
I can use the backing up technique for my application, but it seems that 'position' should be able to use the space as a search character.
I use the position function that way and it works for me. And I tested it with a single space character before posting here. Please see the Position function that I posted in my first post here and compare what I am using to what you were using to see if there are any differences in how this function is used.
Mission accomplished. Not sure what the problem was. I also learned that the position function can work from the back of the string.
Retrieving data ...