Best way to extract specific numbered word from text field
Hi Everyone - first question, please be gentle with me :) :) :)
Initial content in field Customer_description is: "NAME: Richard James (ID 230) COUPON:"
I want to retrieve 'Richard' so I create a field called Calcfirstname
and write the following formula:
let myfirstcount := index(Customer_description, " ");
let mysecondtext := substr(Customer_description, myfirstcount + 1, 90);
let mysecondcount := index(mysecondtext, " ");
substr(mysecondtext, 0, mysecondcount)
Is there not a better quicker way to do that?????
I haven't written any sort of code for a couple of years and fear that I'm as rusty as an old nail :)
Thanks.
6 replies
-
The easiest solution to implement would be something like this...
extractx(Customer_description, "NAME: (\w+)", "$1")
If you want to understand it, here is a resource I like...
-
Hi Sean,
Thanks.
I read some of the info on the linked site and now my brain hurts - I suppose I was hoping for some kind of command like: word(Customer_description, 2) - Oh well that would have been way too easy :)
I'll have to read more of the rexegg site or just make do with ugly code - at least the overhead of a bit of ugly code won't be too bad (I hope).
Have a great weekend. -
Robert,
You're welcome. I felt the same way when I started learning regex. You could always create a user-defined function that takes those 2 arguments . Just in case you haven't found the language reference...
https://ninox.com/en/manual/calculations/reference-of-functions-and-language
You have a great weekend also.
-
This gets me to post 1000!
function word(arg : number) do
extractx(Customer_description, "NAME: (\w+) (\w+) (\(ID \d+\))", text("$" + arg))
end;
word(ArgNum)
That user-defined funtion will return first name with ArgNum = 1, last name with ArgNum = 2 and ID with ArgNum = 3. You just have to declare the function before you use it.
-
Hi Sean - Congrats on your 1000th :) and thanks for the code.
-
Hi Robert, I remembered that the Ninox compiler will automatically cast a number as text if one of the terms is text and the "+" operator is used. So...
extractx(Customer_description, "NAME: (\w+) (\w+) (\(ID \d+\))", text("$" + arg))
can be replaced with...
extractx(Customer_description, "NAME: (\w+) (\w+) (\(ID \d+\))", "$" + arg)
Content aside
- 4 yrs agoLast active
- 6Replies
- 1359Views