Splitting by comma, ignore ""

Hi,

I am splitting data by comma, data is
FirstName,LastName,Mr,T,“Note: , First Line,this is contact detail of T”, test account,test

But I want that data in doube quotes having comma inside should be ignored.

so i want 1 item in array from above data like - Note: , First Line,this is contact detail of T

please suggest

Thanks,
Mohini Nemade

1 Like

Hi @mohininemade301094

Use for each item in strarray

Print the value as string.join(“”.item.toarray)

Thanks
Ashwin.S

This looks contrast buddy
Do we need the one between double quotes or
Other than the one between double quotes

Kindly elaborate a bit more on this pls
Cheers @mohininemade301094

2 Likes

Hi @mohininemade301094

Scenario 1: First you need to split the array delimited by comma
Scenario 2: Use String.Join() to append the the string that you want but of course use foreach for the array of string.

cheers :smiley:

Happy learning :smiley:

3 Likes

this statement is in double qoutes and have comma inside, right now I am getting array items like

  1. Note:
  2. First Line
  3. this is contact details of T

so i want it to Note: , First Line,this is contact detail of T .
please refer string that i am splitting (in question)

Thanks

Not working, it is giving me separate items. I want to treat data inside “” as 1 item even if separated by comma

Hi @mohininemade301094

Use is matches activity and use the expression as \w+.*

Thanks
Ashwin.S

Hello @mohininemade301094
if you are ok with replacing single comma in you item i.e ( “Note: , First Line,this is contact detail of T”) with any other char… then you can try below

String str = original string
String strMatch = System.Text.RegularExpressions.Regex.Match(str, chr(34) & "(.*)" & chr(34)).ToString

for each item in str.Replace(strMatch,strMatch.Replace(",","")).Split(","c)
log message (item)
next item

@mohininemade301094 - you should use Regex.Split for this instead of the normal string.split. This will allow you to isolate the commas to be only those outside of quotation marks. This regex code should grab all commas outside of the quotes (?!\B"[^"]*),(?![^"]*"\B)

I tested this out using your original string: FirstName,LastName,Mr,T,"Note: , First Line,this is contact detail of T" I used Regex.Split(YourString,RegexPattern) and got an array of 5 strings as follows:

  1. FirstName
  2. LastName
  3. Mr
  4. T
  5. “Note: , First Line,this is contact detail of T”

EDIT: the string you have written in the first post won’t work with my regex pattern because it is using weird double quotes. If it does indeed use those weird double quotes, you should use this regex pattern instead: (?!\B("|“|”)[^("|“|”)]*),(?![^("|“|”)]*("|“|”)\B)

Also, the pattern will struggle if there are multiple double quotes it is searching through. If you have the possibility that it will contain multiple double quotes in your input string (e.g. Mr,T,“Test,1”,Address,“Details,here”) then you should first split by finding every second double quote, then run the regex split mentioned in my comment here

Thanks !

yes there is possibility of having multiple double qoutes. can you please advice me on how to manage in that case work flow wise

Thanks

This is replacing all commas…

Thanks

@mohininemade301094 - I thought it was going to struggle with multiple double quotes but it is not. I tested it a few times and it had no issues. It only split on the commas that were outside of double quotes.
(?!\B("|“|”)[^("|“|”)]*),(?![^("|“|”)]*("|“|”)\B)

getting this validation error

Am I putting it in wrong way ?

got it !! let me check and will get back…

Thanks a lot

Yes uipath doesn’t like the double quotes. You have to escape them with even more double quotes which is incredibly annoying and hard to read. Change the regex pattern to be this (copy+paste it): "(?!\B(""|"“|"”)[^(""|"“|"”)]*),(?![^(""|"“|"”)]*(""|"“|"”)\B)"

thanks! but still not working with me.
Can you suggest me how to find 2nd double quote and remove “,” if multiple quotes are there

also can you please share your workflow

Sure thing, here is the XAML: mohininemade301094.xaml (7.6 KB)

thanks a lot ! working :slight_smile:

hi @Dave

It is not working for input string
“, , , , , , , , , ,“”“”,myemail,c@ny.com,myaddress,”“2323street, line1315 text, AK 52525 “”,”“term”“,”“ny”“,123,456,3652”

first array contains
arr(0) = , , , , , , , , , ,"

any idea ?

Thanks

Is that an input string that you are putting in uipath manually? Or is that how it will actually look from the application? There are tons of double quotes in there so it’s really hard to tell. Dealing with all of the escaping double quotes makes putting sample data to test within uipath a huge pain. I would instead create .txt files that emulate exactly how the input string will look in production.

So if in production it looks like this: 123,"1ti,13k",1kd,1k,test then just put exactly that in a notepad file and use the read text file activity to grab the input string. If you did in UiPath you have to make the input string "123,""1ti,13k"",1kd,1k,test" so it’s confusing trying to decipher.