I want to split a text by using mutiple delimeters like Space and NewLine?
hier is an example:
" Hello World.
I am UiPath robot."
I tried to use Split(String," ") but it would put “World.I” together.
Any Idea how I can use the " " and Environment.Newline as seperator at the same time?
That means I will need two arrays to split each one for a line?
Because I wanted to use only one array, so that I can get easelly the first word or the last one for example.
Hi,
Refer this. You can change the delimiters accordingly. The text file contains the content which you gave. test.xaml (6.9 KB) Hope it is helpful.
Thanks.
Thanks you for this example,
I tried this and it worked, hier I am able to add different seperatot like " " or “-” or even Environment.NewLine
I have one question: Could you explain me why we write: ,StringSplitOptions.None?
The option " StringSplitOptions.None " is the default, which means that if two of your specified delimiter are next to each other, you’ll get an element in the array that contains an empty string. The alternative choice is "StringSplitOptions.RemoveEmptyEntries ", which means that a delimiter next to another will be disregarded, and you’ll only get array elements that have non-empty contents.
I’m back to this post and I have one question:
I found this example in the Training, let’s suppose we have this String: Str= “ABCD #12345 is your ID”
So now I need to retreive only the number after the # and I tried this:
Number (is a String) = Str.Split(“#”)(1).ToString.Split(" ")(0).ToString and it didn’t work.
The Solution in the Training was : Str.Split(“#”.ToCharArray)(1).Split(" ".ToCharArray)(0).ToString
Could you please tell me why my solution didn’t work? and why we need to add this (ToChararray)?
Hi ,
As you are splitting the string, the output will be of character array. toCharArray breaks a string and returns a char array containing splitted characters which the string is composed of. The variable Number which you are storing is string so while splitting the character or string should reside on it.
Thanks,