How to get individual values from string

I have a value like

string a= “one two three four”

I want to split with three string variable
like

string first = “one”
string second = “two three”
string third = “four”

string a= “one two three four four”

I want to split with three string variable
like

string first = “one”
string second = “two three four”
string third = “four”

Hi,

Can you try Matches activity with the following settings?

Pattern : "((^\w*?(?=\s))|((?<=\s)\w[\s\S]*\w(?=\s))|((?<=\s)\w*?$))"

Regards,

thanks

How can I use it?

An alternative approach is to split your string, then pick out the pieces you want.

The overview would be:

StringArray = Strings.Split(“one two three four four”)

Then use a for loop and a counter. If the counter =0, it’s the first string, if the counter = StringArray.Lenght -1 the it’s your last string

hi,

The following might help you.

Regards,

What will be the output for it ? @Yoichi

Thanks

Strings.Split(“one two three four four”) is it create string array value?

Hi,

I modified the sample as follows. Can you try?

Regards,

StringArray = Strings.Split(“one two three four four”)

its working good.
counter =0, it’s the first string, if the counter = StringArray.Lenght -1 the it’s your last string

its fine.

but how to get mid of balanced values

@Byte

thanks

its ok but I am not asking that. @Yoichi

Oh, I forget there is no “For” loop, my bad.

Use a While loop, with a counter and an output variable:

int counter = 0;
string middleText = String.Empty;

I didn’t test, but something like:

while (counter < StringArray.Length)

Inside the While:

If (counter <> 0 and counter <> StringArray.Length-1)
Then middleText = middleText & " " & StringArray(counter)

EDIT: Don’t forget to increase the counter inside the while, but after the If. counter = counter+1

Hi @Ajith1,

Let’s say that your string
_MyString = "one two three four"
Now let’s get all the required strings -
_FirstString = Split(_MainString," ")(0)
_SecondString = Split((_MainString.Remove(_MainString.LastIndexOf(" "))),_FirstString)(1).Trim
_ThirdString = _MainString.Substring(_MainString.LastIndexOf(" ") +1)

Hope you will find your solution.

Thanks & Regards,
Apurba

Hi @Ajith1

You can achieve that by below code, try it

variable1 = "one two three four four".Split(" "c)
variable1 = {variable1(0), string.Join(" ", variable1.Except(new string() {variable1(0),variable1(variable1.Length-1)})),variable1(variable1.Length-1)}

Awesome
So if the input is like this
Str_input = “one two three four”

Then use a assign activity like this

Str_value1 = Split(str_input.ToString,” “)(0).ToString.Trim. // which will give us one as output

The another assign activity like this
Str_value2 = Split(str_input.ToString,” “).Last().ToString.Trim

This will give us output as four

And finally a assign activity like this
Str_value3 = String.Join(“ “,Split(str_input.ToString,” “).Skip(0).Skip(Split(str_input.ToString,” “).Count-1))

This will give us output as two three

Cheers @Ajith1