How to get a specific text from a string?

Hi, I am trying to get a specific text from a string, examples of said string would be:
“Document No 9001234567 abc”
“Doc No9007654321abc”

What I want to extract is that string of numbers starting with 900, the 7 numbers after 900 will differ. However, the format of written text is not standardized as seen when comparing my first example to the second one so I cannot simply just do a substring with the same values. Please advice thanks.

Do like this

“Document No 9001234567 abc”.Substring(“Document No 9001234567 abc”.IndexOf(“9”),10)

u can use variable instead of “Document No 9001234567 abc”

3 Likes

Hi, thanks for the reply. Could you explain how .IndexOf(“9”),10 works?

IndexOf(“9”)
Gives you index no of no 9 in string
so by using substring and index it will substring from that index no to 10 digit

1 Like

Thanks for the help it works.

Welcome :blush:

Happy Automation!

Hi @ImPratham45 I have another question if you don’t mind. In situations where I have a few entries to read through and get the strings starting with 900. The first case below was solved earlier but if I get entries such as the next two, is there a way to solve this? The third example basically means there are numbers 9001234567 and 9007654321.

Example:
“Docu No 9001234567 abccc”
“Document No 9001234567 9007654321 abbc”
“DocNo 9001234567/7654321 abcde”

Then what output you want

For cases with multiple numbers included, I could store the numbers into a list for further processing. And also a minor edit to what I said earlier. If an entry has their number like “9001234567/7654321”, the bot will not read this number entirely. It has to be in the format of “900xxxxxxx”.

Example:
“Docu No 9001234567 abccc”
“Document No 9001234567 9007654321 abbc”
“DocNo 9001234567/7654321 abcde” -> Bot will ignore this entry

For that u can use If condition

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