cancel
Showing results for 
Search instead for 
Did you mean: 

Extract part of string?

Nmatan
Deputy Chef I
Deputy Chef I

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!

1 ACCEPTED SOLUTION

shivakumara
Executive Chef II
Executive Chef II

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.



String slicing.PNGString Slice2.PNG

Thanks and Regards,
Shivakumara A

View solution in original post

3 REPLIES 3

mppowe
Executive Chef I
Executive Chef I

Hi Nmata, what about .slice?  Like

<your variable>.slice(0,500) 

Or if you need to protect against nulls

<your variable>&.slice(0,500)

shivakumara
Executive Chef II
Executive Chef II

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.



String slicing.PNGString Slice2.PNG

Thanks and Regards,
Shivakumara A

Nmatan
Deputy Chef I
Deputy Chef I

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!