PPIM_RPA
(PPIM RPA)
August 22, 2023, 5:14pm
1
Happy Tuesday,
Per row, the bot outputs in string format lists of animals, ex:
There are 2 cows, 1 horse, 1 pig, 3 ducks.
There are 1 chicken, 4 horses, 3 cows, 2 pigs.
How to add an ‘and’ before the last # in the string?
For example, it should be … and 3 ducks. … and 2 pigs in examples above.
Thank you, as always.
Regards,
@PPIM_RPA
String.join(“and”,arrayvarable)
Gives you the expected output
PPIM_RPA
(PPIM RPA)
August 22, 2023, 5:26pm
3
The list is in string format and i want the ‘and’ just before the last number only
PPIM_RPA:
There are 2 cows, 1 horse, 1 pig, 3 ducks.
There are 1 chicken, 4 horses, 3 cows, 2 pigs.
Hi @PPIM_RPA ,
Could you provide the expression you are currently using that gives out the output in the above format ?
Could also perform something in the below manner :
String.Join(", ",yourListVar.SkipLast(1).append("and "+yourListVar.Last).ToArray)
PPIM_RPA
(PPIM RPA)
August 22, 2023, 5:34pm
5
You helped me with this: String.Join(“, “,dt_CSV.AsEnumerable.Where(Function(x) {“Endangered”, “Threatened”}.Contains(x(“ESA Listing Status”).ToString)).GroupBy(Function(x)x(“Lead Office”).ToString).Select(Function(x)x.Count.ToString + " " +x.First.Item(“Lead Office”).ToString + " (” +String.Join(”, ",x.Select(Function(y)y(“Common Name”).ToString).ToArray)+ “)”))
Just want to add an ‘and’ before the last number if possible for grammatical sake
postwick
(Paul Ostwick)
August 22, 2023, 5:36pm
6
System.Text.RegularExpressions.Regex.Replace("one, two, three",",(?=[^,]+$)",", and")
PPIM_RPA
(PPIM RPA)
August 22, 2023, 5:40pm
7
Thank you. The numbers are written out like 1, 3, or 2, and change every time. But I was wondering if Regex.Replace could do this too
postwick
(Paul Ostwick)
August 22, 2023, 6:05pm
8
Yes mine was an example with a static string but you can just replace that with a variable.
PPIM_RPA
(PPIM RPA)
August 29, 2023, 7:08pm
9
Note to self: Read the friendly manual!
Used Regex Replace to find last comma: “,(?=[^,]*$)” and replaced with “, and”
This solved the issue
system
(system)
Closed
September 1, 2023, 7:09pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.