Ajith1
(only test)
December 20, 2019, 8:25am
1
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”
Yoichi
(Yoichi)
December 20, 2019, 8:41am
3
Hi,
Can you try Matches activity with the following settings?
Pattern : "((^\w*?(?=\s))|((?<=\s)\w[\s\S]*\w(?=\s))|((?<=\s)\w*?$))"
Regards,
Byte
December 20, 2019, 8:46am
5
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
Yoichi
(Yoichi)
December 20, 2019, 8:47am
6
hi,
The following might help you.
Regards,
Ajith1
(only test)
December 20, 2019, 8:49am
7
What will be the output for it ? @Yoichi
Thanks
Ajith1
(only test)
December 20, 2019, 8:54am
8
Strings.Split(“one two three four four”) is it create string array value?
Yoichi
(Yoichi)
December 20, 2019, 8:58am
9
Hi,
I modified the sample as follows. Can you try?
Regards,
Ajith1
(only test)
December 20, 2019, 9:02am
10
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
Ajith1
(only test)
December 20, 2019, 9:03am
11
its ok but I am not asking that. @Yoichi
Byte
December 20, 2019, 9:15am
12
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
aanandsanraj
(Anandraj Rajendran)
December 20, 2019, 10:04am
14
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)}
Palaniyappan
(Palaniyappan P )
December 20, 2019, 10:13am
15
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
1 Like