Obtaining last word in a string

Hi all

I’m trying to split a string and obtain the last word. The number of words in the string will always change, but the word I want will always be after the same word, e.g. “[Mr Fake Name & Mrs Fake Name (code: 12345)]”

With the changing number of words in the string in mind, how would I obtain the 12345?



there are several ways to achieve this. Simple oneliner would probably be to create a substring of characters that come after the last whitespace.
lastWord = wholeString.Substring(wholeString.LastIndexOf(" ") +1) // +1 is there in case you wholeString happens to be just single word

In your case this would include the brackets also “12345)]” so you would have to remove them.

There is an Replace activity in UiPath which can be easily used to manipulate strings.
Input= your sentence
Pattern=“[^0-9]” // removes everything except numbers
Replacement= “”
Result= myCode

Ps. If your input sentences are all of this format => you only want the numbers presented then the Replace is all you need.



Amazing, thank you :slight_smile:

I have date and time at the end and want to capture this whereas the previous are names whose letters change. Kindly help
Eg: “abc fake 17-01-2018 09:45” or fake “17-01-2018 15:30”
I just want date and time.

Hi Kruttika,

Please use regex pattern to get date and time.
let me know if you need pattern as well.