I have looked through the ESRI community board and other S123 documentation for this, but I am either blind, or it doesn't exist?
I am looking to generate an acronym from a string field to populate into a new field that would generate automatic point IDs. The acronym would take the first letter of each word. One more note, this form will NOT be used in Survery123 application but instead on the web, so JS function will not work. @Katie_Clark, tagging you here because you're my fav MVP pal :).
Example below, bold are the fields in the form & red text is in a repeat
example 1:
Name or Entity: John Doe
LocationCounter: 1 <--this is autogenerated from the count() function
Point ID: JD-1 <-- this would be generated from the concat() and also the acronym biz I am asking about
example 2:
Name or Entity: Some Business Name
LocationCounter: 2 <--this is autogenerated from the count() function
Point ID: SBN-2 <-- this would be generated from the concat() and also the acronym biz I am asking about
Solved! Go to Solution.
Hmmm, maybe you could do something with the substr function?
Unfortunately, as far as I know there still isn't a built-in split function that you could use to easily get each word using the space as a delimiter. But the substr function gets you part of the way, at least!
Hmmm, maybe you could do something with the substr function?
Unfortunately, as far as I know there still isn't a built-in split function that you could use to easily get each word using the space as a delimiter. But the substr function gets you part of the way, at least!
@Katie_Clark, thanks for referencing this! I think using this should work well, even if I am just pulling the first 2-3 characters from the name field!
Thanks!
Katie is correct. You'd be looking for split() but we don’t have that yet (ironically, we have join…)
You also have an unknown number of words to work with. If it was just a first name and last name, then the solution would be set up two different fields and use substr() on the first letter.
While not as clean as your example, you could use substr() on the first, middle, and last character of your text field. That would make them more IDs than acronyms, but it’s at least doable. Rather than using a static value in substr, you’d use a dynamic count of the characters in the text box (with a little math).
You could also use regex, but that's more opaque than Katie's method. Would give you geek programmer points though 🙂
@abureaux, I ended up using the first three characters of the name field. I opted to not add extra fields for first and last name, since sometimes it will be an entity name that is used. This particular form is already field and repeat heavy, so doing my best to keep the parent record simple. Hopefully we can get a split() function, which would be super helpful.
@GregKeith, I do have some regex in there already, but nothing I wrote myself, those things are so outside of the box to me.
Thanks for the help and thoughts y'all!
For anybody wondering, I manage to do it with a JavaScript function and a calculate field with pulldata(@javascript,....). But the split() function would definitely be a good addition.
My input text was scientific names of species that people have to write like this "Genus Species"
To have the acronyms, I added this script :
function acronyms(input_text) {
// Split the input text into words
var words = input_text.split(" ");
var acronyms = "";
// Extract the first letter of each word and append to the acronyms string
for (var i = 0; i < words.length; i++) {
if (words[i].length > 0) {
acronyms += words[i][0];
}
}
return acronyms;
}
In the result calculate question : pulldata("@javascript", "acronyms.js", "acronyms", ${species})