As a follow up to my parsing question, is there an easy way to identify if the field entry starts with a letter? I can do a case for all 26 letters, but I was hyphen for something more graceful.
How about something like this?
myInput = "z123";
~firstChar = Left(myInput; 1)
(~firstChar >= "a" ) and (~firstChar <="z"); 1;
PatternCount ( Left ( yourFieldHere ; 1 ) ; "abcdefghijklmnopqrstuvwxyz" )
You can certainly use a "CF" for something like this, but going back to the micro-service approach from your other posting, notice how easy the code below is to read (you would still call this from FMP).
From FMP, you would just pass the string variable to the micro-service method (function) using FMP's INSERT FROM URL GET Syntax.
The built-in Character class looks at a single character. So, line 2 above just takes the character at position zero, the first character, and checks to see if it's alphabetic. Note the easy-to-understand other things you can do with a character (for just starting with "is") in the list below. You could also ask if it's a digit, a letter, letterOrDigit, lowerCase, upperCase, titleCase,....etc.
Super clear, right?
Need to do something else? A partial list of the Character class' methods for "is" something include...
(all built in with no re-inventing the wheel.)
All callable from FMP!
Not to criticize in any way using something like PatternCount, which is probably the best way to do what you want directly in FMP, but with that function, you have to look at what's going on and "understand" what's being done since it's only an indirect solution to the problem. By "indirect", I only mean (again, no criticism) that you're using more general functions to "do something" and then you have to "interpret" the code and what it's doing -- which makes the code less clear.
Maybe it’s just my years of FileMaker experience, but pattern count seems pretty clear to me. Any time that I feel such a calculation isn’t sufficiently clear, I can add an inline comment very easily.
By the way, you are indeed criticizing the use pattern count—in a helpful and constructive manner and that’s what should happen in such a discussion as this.
We need to point out the negatives that we see in a given suggestion. That helps the reader in making an informed choice.
It's all relative. I did say PatternCount() was probably the best way to do this simple task.
The beauty of this forum (and FMP itself) is the wide range of options available.
Thanks for your note.
I could not get either calculation provided by TomHays or philmodjunk to work. However,
Case ( Left ( myField ; 1 ) ≥ "a" ; 1 ; 0 )
did work with every record I created.
Silly me, I have the parameters in the wrong order. It’ll work if you put the alphabet first.
character = Left ( the::field ; 1 ) ;
If ( Filter ( character ; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ) = character ; 1 ; "" )
Filter() gives you very granular control over what is a match.
You can't use "shorter string first" for PatternCount
I like to omit Case(;1;0) for returning boolean value.
Please don't get upset with the messenger, but some of these replies underscore my point about the code not really being readable or maybe just tested.
The Java code is totally clear on its intent (again, I am NOT saying the micro-service approach makes super duper sense for such a minor calculation).
Plus, you can test the code interactively right from the command line in Terminal.
So, what I am saying is that it would be great if in FMP 17, 18, ...., etc, if there were string/character functions that were more in depth for greater code clarity.
My two (or maybe four) cents.
And, just to be complete, a micro-service approach could be a library of added character and string functions not easily done in FMP.
So, the INSERT FROM URL command could call any method you create, but assuming you create a method called: "isFirstCharacterAlphabetic()" to mimic what's in Java (not required, but the naming convention is standard), you might have an INSERT URL like this with a simple GET Request:
Once you got this highly-specific method working (EASY!), you could create a more general, powerful, method, like "isAlphabeticAtIndex()". Then, you could pass the string and the index in the string as a second GET parameter. Your micro-service logic would, again, abstract the complexity (testing for index out of bounds, etc.).
Once you've abstracted the complexity to your FREE external service, you or thousands of clients could access from any HTTP-enabled client (Terminal, FMP, Browser, other programs, ...). In a practical sense, using a service approach for custom functions makes configuration simpler since the service sits higher in the hierarchy and all the clients use the same URL to access it. Good thing: The service is independent of FMP or any other application program. Thus, if you need to change the service code, you change the service code in one place for all clients!
Retrieving data ...