Skip to main content
Inspiring
February 14, 2012
Answered

Regex Help: Remove "" quotations from input name

  • February 14, 2012
  • 2 replies
  • 648 views

I'm having trouble getting a program to remove the "" from a string that's being ready from a .csv file.  Basically, what's happening is, sometimes, when someone saves a .csv using a spreadsheet program, it adds the "" before and after each entry (so basically what should be data,data2,data3 comes out as "data","data2","data3").  How do I remove the "" from the variable so that my script properly accesses the data it needs?  I have an example of what I've tried below to test it:

for(i=0;i<bits.length;i++) {

     bits.replace(/"(?=[^\[]*\])/g, ''); //remove "" quotations

     alert(bits);

}

Unfortunately, this doesn't appear to do anything.  No error and the "" are still in the variable when the alert displays.  What am I doing wrong?

dgolberg

This topic has been closed for replies.
Correct answer Paul Riggott

You are not writing the new value back to the array so when you do the alert that value has not changed.

Try this..

for(i=0;i<bits.length;i++) {

     bits = bits.replace(/"/g,''); //remove "" quotations

     alert(bits);

}

2 replies

Inspiring
February 14, 2012

It's probably simpler if you do something like

     bits = bits.replace(/"/g, '');

Of course, this does not take into account csv files where the columns may include " or , characters...

dgolbergAuthor
Inspiring
February 14, 2012

Lol, I must have been a lot more tired than I thought when trying to write that.  Thanks for the help guys!  Can't believe I missed the fact I wasn't re-writing the array, lol! 

I do like the shorter version you used xbytor; and the .csv file is mostly file names and action names, so there shouldn't be any stray quotations or commas, so it works perfectly.

Paul Riggott
Paul RiggottCorrect answer
Inspiring
February 14, 2012

You are not writing the new value back to the array so when you do the alert that value has not changed.

Try this..

for(i=0;i<bits.length;i++) {

     bits = bits.replace(/"/g,''); //remove "" quotations

     alert(bits);

}