String Manipulation in DataTable Question

Hi Guys,
I’m extracting the Last Name but as can be seen there are cells with three words.
For cell with two words value it’s straight forward.
For cell with three words value, I want the middle value and last value
In this case (per ss), I want to extract: “Van Oord” as Last Name

Using either row("Name").ToString.Split(" "c).Last
or row("Name").ToString.Split(" "c).(1) will only extract one word value.

Can someone guide me on what to do if I want the middle and last value as Last Name?
Best I can think of atm is to use if condition to count substrings where if there are three values I extract index (1) and (2) as Last Name.

Update/Edit: The String Manipulation needs to work on both scenarios where there are two values words and three value words (in for each loop)

image

Additional reference:

Hi @Dillon_Marius

Can you try with this

inputString = "Lakshman Reddy Tetala"
outputString = inputString.Substring(inputString.IndexOf(" ") + 1)

Hi @lrtetala

Appreciate the reply.
Could you show this formula in for each row form? (forgot to mention in the post)
Also does it work on both scenarios where there are two words value and three words value?

Thanks

@Dillon_Marius

CurrentRow(0).ToString.Substring(CurrentRow(0).ToString.IndexOf(" ")+1)

Input

image

Output

image

Awesome @lrtetala !

Thank you for the tailored answer.
Appreciate you!

1 Like

For Windows project (not Windows Legacy), you can also use:

row("Name").ToString.Split(" "c, 2).Last

The “2” argument is to indicate that you only want the string split in two parts.

image

image

1 Like

Wow.
That’s equally awesome! Easier to digest also. Thank you and Cheers @ptrobot !

1 Like

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