Expand|Select|Wrap|Line Numbers
- var colArr = new Array();
- colArr = RemoveEmbeddedCommas(caseLogArr[i]);
I have a string that has fields delimited by commas, however, I also have fields that have quotes surrounding the text and that text contains embedded commas. A typical string segment would look like this...
Monday,"January 1, 2007",Tuesday,"January 2, 2007" etc.
My function eliminates the embedded commas so that I do not have separate fields for like ["January 1] and [2007"].
Here is the function...
Expand|Select|Wrap|Line Numbers
- function RemoveEmbeddedCommas(colStr)
- {
- var colArr = new Array();
- var newArr = new Array();
- var colArrIndex;
- var quoteIndex = 0;
- var newArrIndex = 0;
- var matchQuoteFound;
- colArr = colStr.split(",");
- for (colArrIndex = 0; colArrIndex < colArr.length; colArrIndex++)
- {
- if (colArr[colArrIndex].indexOf('"') == 0 && colArr[colArrIndex].indexOf('"',1) == -1)
- {
- quoteIndex = colArrIndex + 1;
- newArr[newArrIndex] = colArr[colArrIndex];
- matchQuoteFound = false;
- while (matchQuoteFound == false)
- {
- newArr[newArrIndex] = newArr[newArrIndex] + " " + colArr[quoteIndex];
- if (colArr[quoteIndex].indexOf('"',1) > 0)
- {
- matchQuoteFound = true;
- }
- quoteIndex++;
- colArrIndex++;
- }
- }
- else
- {
- newArr[newArrIndex] = colArr[colArrIndex];
- }
- newArrIndex++;
- }
- return(newArr);
- }
Thanks for any help,
Joe Ruvolo