Hello team, pls provide solution for this string manipulation.Tq

Mr Soot Princeer 73236SE023 3

Antony Graspe 84678SE020 1

Mr Bake wood Justin Loc 7778SE0579 2

From above all data i want split each data and assign to variables like
ex: Name: Mr Soot Princeer
Ref no.: 73236SE023
Stays: 3
pls provide solution .Tq

@lakshmi_narayana_ch

Please use this regex

Name: varName = System.Text.RegularExpressions.Regex.Matches(str,"([\w\s]+)\s+([\dA-Z]+)\s+(\d+)")(0).Group(1)

ID: varID = System.Text.RegularExpressions.Regex.Matches(str,"([\w\s]+)\s+([\dA-Z]+)\s+(\d+)")(0).Group(2)

Num: varNum = System.Text.RegularExpressions.Regex.Matches(str,"([\w\s]+)\s+([\dA-Z]+)\s+(\d+)")(0).Group(3)


image

cheers

hello @lakshmi_narayana_ch you can split the information on the basis of space , suppose str_var =“Mr Soot Princeer 73236SE023 3” . Create array of string type str_array , and assign the value to the array of string type = str_array = split(str_var," “)
Now str_array have =[“Mr”, “Soot” , “Princeer” , “73236SE023” , “3” ] then do create a variable of struing data type example name and then do this name = str_array(0).ToString +” "+ str_array(1).ToString + " "+str_array(2).ToString
and extract information from the array according to your requirement.

I extracted basic data(Mr Soot Princeer 73236SE023 3) using matches activity and iterated using for each. if i assign variable to extract individual data it is showing error that not accepting to convert string to int. Now how can i use your expression and extract individual data.
image

Hi,

Can you try the following sample?

mc = System.Text.RegularExpressions.Regex.Matches(strData,"(?m)^(?<NAME>.*)\s+(?<REF>\w+)\s+(?<STAY>\d+)\s*$")

Then, iterate MatchCollection : mc. Let’s say m as each item.

m.Groups("NAME").Value
m.Groups("REF").Value
m.Groups("STAY").Value

returns each matched string.
The above sample outputs the following sheet , finally.

image

Sample20230401-4L.zip (3.1 KB)

Regards,

@lakshmi_narayana_ch

My expression is to be used in assign activity…and you have to give your string in place of str…basically it would be currentitem.value…and in for each properties change the type argument to system.text.regularexpressions.regex.match

Then it would give you each value…in the loop

Cheers

thank u for info. but i am getting raw data from using matches activity and using for each. showing error like this
image

Hi,

Probably, we can use the above expression with Assign activity instead of Matches activity you use.

mc = System.Text.RegularExpressions.Regex.Matches(strData,"(?m)^(?<NAME>.*)\s+(?<REF>\w+)\s+(?<STAY>\d+)\s*$")

Then iterate mc using ForEach activity. Please set Match type at TypeArgument.

we can get each value using the following expression.

m.Groups("NAME").Value
m.Groups("REF").Value
m.Groups("STAY").Value

Regards,

Hi @lakshmi_narayana_ch ,

Maybe we can use the Split function as well, if the Ref No. and Stays are always in the last positions. As mentioned by @Ankit_Chand , but in a dynamic way we can use the below :

  1. Stays :
Split(yourInputStr.Trim).Last
  1. Ref No. :
Split(yourInputStr.Trim)(Split(yourInputStr.Trim).count-2)
  1. Name :
String.Join(" ",Split(yourInputStr.Trim).take(Split(yourInputStr.Trim).count-2)).Trim

Debug Panel Output :
image

An additional check on the Split to see if there are 3 or more splits would be necessary at first, then the extraction part as provided above could be done :

Split(yourInputStr.Trim).Count>=3

Let us know if you are able to understand the above approach.