Split string by space don´t work. How do I find the character?

I have a name stored as a variabel (as a string), it’s both first and lastname separated by space. I now try to break them a part in to two variables, firstname and lastname. But uipath don´t reqonice the space, I can´t use mystring.Split(" ".ToCharArray)(2).ToString

How can I find out what character other then space it can be?

mystring.split(" "c).toArray()(2)

You can split it this way for any whitespace, where MyVar is your string variable you’re trying to split.

System.Text.RegularExpressions.Regex.Split(MyVar, "\s+")

1 Like

But I think that your array only contains two values (firstName, lastName), so your array only has 0 and 1 position.

fName = mystring.split(" “c).toArray()(0)
lName = mystring.split(” "c).toArray()(1)

Hi @Zlotzky,

Try this

FirstName = Text.Split(New Char() {" “c}).ToArray()(0)
LastName = Text.Split(New Char() {” "c}).ToArray()(1)


Hi @Zlotzky

please check this Image



FirstName = Fullname var.split(" “c)(0)
LastName = Fullname var.split(” "c)(1)


Thanks but I´d tried with that. the problem is that it does not reconize the space so even with split(" "c) it remains as both first and lastname


See my solution. It accounts for any whitespace (tabs, newlines, spaces, etc.). It also accounts for multiple spaces, so string "hello there, friend" would split to {“hello”, “there,”, “friend”} despite the variable number of spaces.

Here´s a pict, I´t don´t split the space.

I get a error message that I´m not certain of. se pict above in message no 7

The error message when applying Anthony_Humphries answer shows that your variable type should be an Array of String rather than simply a String.

If you want to assign directly the firstname and lastname values, please apply proper index:

System.Text.RegularExpressions.Regex.Split(MyVar, “\s+”)(0)
System.Text.RegularExpressions.Regex.Split(MyVar, “\s+”)(1)

@msan thanks!

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