How to get specific number from a string

Hi all,

I’m currently working on an issue, which needs to get specific number in a string.

The string would be like: overall 54 records, 3 pages in total.

I need to get the “3” out of this sentence. However this expression is not working: integer.parse(right(“page”,5))

Do you know how to deal with this issue? Thanks a lot.

@Paddi

You can try this

\d+(?= pages)

System.Text.RegularExpressions.Regex.Match(str,"\d+(?= pages)").Value

cheers

1 Like

Hi

Hope the below expression would help you resolve this

Use a assign activity like this

Str_value = System.Text.RegularExpressions.Regex.Match(str,”\d+(?=\spages|pages)”).Value

Where str_value is a string variable

The reason why ur expression was not working is
this expression attempts to extract the rightmost 5 characters of the string “page” (which will be “page” itself), and then convert them to an integer. Since “page” cannot be parsed as an integer, this expression will throw a FormatException at runtime.

Cheers @Paddi

1 Like

@Paddi ,

Split(Split("overall 54 records, 3 pages in total."," pages")(0),"records, ")(1)

image

Regards,

1 Like

Hi @Palaniyappan,

Really appreciate your answer, it’s working.

1 Like

Glad it got resolved @Paddi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.