Triming extra characters ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I have a csv file which as following output :
"REC00001.CSV","Pipe","25 x 2.5 mm","LP602","LP602","02/11/2004 15:15:04"

I need to remove from that string doucble quote char.

In order to read my file I use following code :

sRead = m_IOStream.ReadLine
'- as it is a CSV file format, we need to identify the separator
field and split the string in array for ready data

sRead = sRead.Trim(sTrimChar)

HOw to define my sTrimChar delimiter to remove double quote in my string.?
I have tried "''" but it fails

thnaks for your help
regards
serge
 
mihael,

What effect does that syntax does ?
especailly the \ char, is it EScap sequence ?

I am using VB.net for your info
But I will give a try anyway
 
Be aware that the Trim function will only remove the characters from
the beginning and end of the string.

If you wish to remove all occurences of the quotation mark, try this:

sRead = sRead.Replace("""",String.Empty)

Note that the first argument above has 4 quotation marks.

There may be other ways to do this that have better performance.

Chris
 
Be aware that the Trim function will only remove the characters from
the beginning and end of the string.

If you wish to remove all occurences of the quotation mark, try this:

sRead = sRead.Replace("""",String.Empty)

Note that the first argument above has 4 quotation marks.

There may be other ways to do this that have better performance.

Chris
 
If you have a small budget, but at least a budget, my suggestion is to
actually buy a package to handle all this nastiness for you instead of
trying to guess at the proper handling because at best, you'll do it
very inefficiently, and at worse, you'll do it inefficiently and
incorrectly. As for the answer to your question, if you're just bound
and determined to do it wrong, split on a comma, then on each value in
the array, you'd want to trim ", but then replace "" with ". Even at
that, you're breaking atleast 3 rules of csv parsing.
 
Serge,

yes \ is a escape sequence in c#/c++. I think the way Chris does it is the
best. He's also correct that Trim() only trims the leading and trailing
characters. Sorry, I forgot that one...

Regards,
Michael
 
just for my knowlege, could you explain me why the proposiion of chris is not
suitable?

I means what rules are you talking about, I am interresting to know?
 
Trimming quotes from the beginning and end of a column will remove the
quotes even if they're supposed to be there, like on a column "Mary
said, ""Go away!""". Splitting on a comma will mess up columns with
commas in them, like "$100,000". Using ReadLine will mess up columns
that can contain carriage returns and new line characters in the data,
which is completely valid as long as they're contained in text qualifed
data using quotes. In quite a few instances, leading and trailing white
space in non text qualified data should be trimmed. These rules are
very valid, and are why I'd suggest not making your own csv parsing
routines, and instead just buying a parser where someone has already
done all this work for you, and most likely, a lot more efficiently
since they weren't under a deadline restriction to just get something
that kind of works out.

Here's a site that I consider pretty decent describing some of the de
facto standard rules of csv data.

http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
 
Back
Top