Hi all,
I have a string of the following format:
Banana 2. Bread 3. Cheese 4. Apples
I would like to split this string into the following: [“Banana”, “Bread”, “Cheese”, “Apples”]
Essentially, I would like to split by the numbers and the dot (i.e. 1. or 2.)
How would I do so?
Thank you!
hi @indie9876
use regex pattern like this
then use for each actvity to iterate through each value
1 Like
Hi,
Thank you for the swift response! I forgot to clarify above, but my string does include numbers too. For instance:
Banana 2. Bread 3. Apples 4. 512 Grapes 5. 612 Oranges
How would I code this?
So u need that numbers to be extarcted
Yes I would like the list to be: [Banana, Bread, Apples, 512 Grapes, 612 Oranges]
Yoichi
(Yoichi)
September 1, 2020, 6:42am
6
Hi,
Hope the following helps you.
System.Text.RegularExpressions.Regex.Split(text,"\d\.").Select(function(x) x.Trim()).Where(function(y) not String.IsNullOrEmpty(y)).ToList()
Main.xaml (5.8 KB)
Regards,
2 Likes
Hi,
What should the variable type of the list be? It is coming up with errors saying that it is of the wrong type
Thanks!
Yoichi
(Yoichi)
September 1, 2020, 6:50am
8
Hi,
This expression returns List<string>
type. Do you have an error in the above attached xaml file?
Regards,
1 Like
Works Perfectly Now! Thank you so much
Hi again,
I was wondering if you would be able to help me with the following:
I would like to separate the text in between two particular strings and place them in a list
The form is: 1. Apple Instructions Place the Apple in the pan 2. Banana Instructions Chop up the banans 3. Pear Instructions Peel the pear
I would like it to be organised into the following list: [Apple, Banana, Pear]
Essentially, how do I extract the text between the number point (e.g. 1.) and the static word (Instruction)
Thank you!
Yoichi
(Yoichi)
September 1, 2020, 7:30am
11
Hi,
If you want to extract just a word next to number and period, the following expression will work.
System.Text.RegularExpressions.Regex.Matches(text,"(?<=\d+\.\s*)\w+")
Main.xaml (5.9 KB)
Regards,
1 Like
Hi,
What if there are multiple words I would like to extract?
E.g. 1. Bananas that are ripe Instructions Peel the bananas
Yoichi
(Yoichi)
September 1, 2020, 7:47am
13
Hi,
Can you show me output what you expect for the above example?
Regards,
Hi I would like to see a list like this: [“Bananas”]
Yoichi
(Yoichi)
September 1, 2020, 7:56am
15
Hi,
Does the following expression (at #11 ) work for it?
System.Text.RegularExpressions.Regex.Matches(text,"(?<=\d+\.\s*)\w+")
If you need single string as result, the following will work.
System.Text.RegularExpressions.Regex.Match(text,"(?<=\d+\.\s*)\w+").Value
Regards,
system
(system)
Closed
September 4, 2020, 7:57am
16
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.