cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gjeh
Responsive Resident
Responsive Resident

Setting up specific expression to remove comma inside strings but not comma outside string

Hi,

 

I'm trying to come up with an expression that I can run over each line in a csv file.

example line in csv:

 

 

 

Bill Carpenter, "Fighter,Jet", 13.3, "HR, Manager", Apples

 

 

 

as we notice some items are provided with " "  (which obviously i can easily replace with replace by "") however as you can see the Fighter Jet and HR Manager contain a  ,  aswel.   Im not guaranteed each line in the csv has the same format (ie;  " " data is on the same place and wether a , is inside a string at all). 

but i want to strip  all   comma's  (,) inside string values ""   aswel as remove all "".  

1 ACCEPTED SOLUTION

Accepted Solutions
PrasadAthalye
Community Champion
Community Champion

See if below helps... You can put it in a loop for each row in CSV file..

 

Using split to put it in Collection

split(string(variables('varData')), '"')
 
and then replace commas,  This will replace all commas, but you can then run a loop on array to take further action
replace(variables('TextAfterSplit'), ',''')
 
 
 

FlowSplit.png

 

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

4 REPLIES 4
PrasadAthalye
Community Champion
Community Champion

See if below helps... You can put it in a loop for each row in CSV file..

 

Using split to put it in Collection

split(string(variables('varData')), '"')
 
and then replace commas,  This will replace all commas, but you can then run a loop on array to take further action
replace(variables('TextAfterSplit'), ',''')
 
 
 

FlowSplit.png

 

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
gjeh
Responsive Resident
Responsive Resident

thanks, this helped me do exactly what i wanted!!

hi @PrasadAthalye 

Thank you for the suggestion - seems to be on the right path for my particular CSV problem, similar to @gjeh 

I've tried splitting my CSV data along the double quotes (") and managed to isolate the values that have unwanted commas inside.

As you mention, the final "ReplacedText" is my CSV file entirely missing commas - which I still need later.

However, in the Apply to Each current item, it just seems like its every other item is the one I would like to replace the comma - example below where I would like to keep my CSV data intact (I still need commas) but only replace in every other "Value", and then finally bring everything back together as a regular CSV to parse later in the flow.

Apply to Each 1/10 - CSV Data

> Apply to Each 2/10 - Value,1 (Should be Value 1)

 > Apply to Each 3/10 - CSV Data

  > Apply to Each 2/10 - Value,2 (Should be Value 2)

etc.

Then finally I want to end up with CSV Data,Value 1,CSV Data,Value2, etc.

@virakones - Can you please open a new question for this? This already has a solution identified... We will work on the new thread to look at your case..

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

Helpful resources

Announcements
Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (2,195)