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
Super User
Super User

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
Super User
Super User

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

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
Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,252)