a month ago
Hi all,
New to Workato.
I have a requirement to extract the first 500 characters of a string, I tried to do this with a formula but for some reason it's not working:
String.scan(/.{0,500})
The regex seems to be correct, but the end result is empty - not posting anything.
What am I doing wrong?
Appreciate any help!
Solved! Go to Solution.
4 weeks ago
Hi @Nmatan ,
Another simple way to achieve this is by using...
Using []
Example: <your String>[0..499]
Meaning: Starting from the index 0 to till 499 characters ( total 500 characters)
---------------------------------------------------------------------------------------------------------------------
Image_1 : without explicitly converting it to (Data Type: string) gives the result if the input is available.
Image_2: With explicitly converting it to (Data Type: string) helps in handling empty data or null values.
Thanks and Regards,
Shivakumara A
a month ago
Hi Nmata, what about .slice? Like
<your variable>.slice(0,500)
Or if you need to protect against nulls
<your variable>&.slice(0,500)
4 weeks ago
Hi @Nmatan ,
Another simple way to achieve this is by using...
Using []
Example: <your String>[0..499]
Meaning: Starting from the index 0 to till 499 characters ( total 500 characters)
---------------------------------------------------------------------------------------------------------------------
Image_1 : without explicitly converting it to (Data Type: string) gives the result if the input is available.
Image_2: With explicitly converting it to (Data Type: string) helps in handling empty data or null values.
Thanks and Regards,
Shivakumara A
3 weeks ago
My apologies @mppowe and @SHIVA for not responding, it looks like I don't get any notification email when a comment is added? (New to these forums).
@mppowe I tried that - it seems to have captured the first sentence of the string only.
I should've mentioned, but the string in this case is a long text area field, so it can have multiple lines. So for example, out of the following:
"123412341234
qwerqwerqwer
asdfasdfasdf
zxcvzxcvzxcv"
It only captured:
123412341234
Even though the regex was correct.
However it looks like @SHIVA did work - and it captured everything correctly.
Many thanks for both of you for your assistance!