voxter
(voxter)
September 18, 2023, 10:55am
1
Hi. I have a paragraph, and I need to extract first word for each line. Please help.
Example: I have this paragraph, it is assign in sample_text
variable:
US, John, Wa
EU, Miu, KO
JP, Got, Ko
KR, kiioo, hu
Now I need to extract US
, EU
, JP
, KR
and then concat it into a string: US_EU_JP_KR
.
It will be very nice if I can do it by one line with assign
activitiy, like as: result = from sample_text do ...
.
Please help
Anil_G
(Anil Gorthi)
September 18, 2023, 11:04am
2
@voxter
Please try this
String.Join("_",System.Text.RegularExpressions.Regex.Matches(str,"^\w+",RegexOptions.MultiLine).select(function(x) x.Value))
Str is the variable containing your text…assumption is there are new lines
Cheers
RajKumar_DC
(RajKumar Durai)
September 18, 2023, 11:20am
3
Hi @voxter
Input:
Output:
Workflow
Expration
String.Join("_",st.Split(Environment.NewLine.ToCharArray).Select(Function(x) x.Split(","c)(0).ToString))
st = your input string value variable
Thanks,
Hope this helps you
Use a assign activity like this for a one line expression
Hope you have the variable saved as str_input
Str_output = String.Join(“_”, System.Text.RegularExpressions.Regex.Matches(str_input.ToString, “+“).Select(Function(a) a.Value).ToArray())
To just explain
String.Join(“_”, your array variable) will help you to join the array of words you have found
Inside this join method we are using Regex method to get the first set of words from your input string
Regex explanation
You can try this expression in regex101.com website
Hope this explains
Cheers @voxter
neha.upase
(Neha Upase)
September 18, 2023, 11:21am
5
Hi,
Assuming you have your paragraph stored in a variable called sample_text.
Create an Assign activity and set the “To” field to your result variable, let’s call it result.
In the “Value” field of the Assign activity, you can use the following expression:
result = String.Join(“_”, sample_text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(line) line.Split(","c)(0).Trim()))
@voxter Please find Solution xaml
Main.xaml (6.8 KB)
Hello @voxter
Try this regex method with Join String
String.Join("_",System.Text.RegularExpressions.Regex.Matches(YourString,"^\w+|(?<=\n)\w+"))
Parvathy
(PS Parvathy)
September 18, 2023, 12:41pm
8
Hi @voxter
sample_text= "US, John, Wa
EU, Miu, KO
JP, Got, Ko
KR, kiioo, hu"
result= String.Join("_",sample_text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(line) line.Split(","c)(0).Trim()))
Hope it helps!!