471,339 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Triming extra characters ???

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
Jul 21 '05 #1
11 2162
Serge,

try the following:

sTrimChar = "\"";

Regards,
Michael

"serge calderara" <se************@discussions.microsoft.com> schrieb im
Newsbeitrag news:0B**********************************@microsof t.com...
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

Jul 21 '05 #2
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

"Michael Groeger" wrote:
Serge,

try the following:

sTrimChar = "\"";

Regards,
Michael

"serge calderara" <se************@discussions.microsoft.com> schrieb im
Newsbeitrag news:0B**********************************@microsof t.com...
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


Jul 21 '05 #3
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

Jul 21 '05 #4
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

Jul 21 '05 #5
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.

Jul 21 '05 #6
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

"serge calderara" <se************@discussions.microsoft.com> schrieb im
Newsbeitrag news:CA**********************************@microsof t.com...
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

"Michael Groeger" wrote:
Serge,

try the following:

sTrimChar = "\"";

Regards,
Michael

"serge calderara" <se************@discussions.microsoft.com> schrieb im
Newsbeitrag news:0B**********************************@microsof t.com...
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


Jul 21 '05 #7
thanks chirs that works

serge
"Chris Dunaway" wrote:
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

Jul 21 '05 #8
just for my knowlege, why 4 quaotation marks are required and not only the
single " ?
"Chris Dunaway" wrote:
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

Jul 21 '05 #9
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?

"shriop" wrote:
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.

Jul 21 '05 #10
Serge,

that's how vb.net escapes double quotes.

Regards,
Michael

"serge calderara" <se************@discussions.microsoft.com> schrieb im
Newsbeitrag news:D4**********************************@microsof t.com...
just for my knowlege, why 4 quaotation marks are required and not only the
single " ?
"Chris Dunaway" wrote:
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

Jul 21 '05 #11
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

Jul 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by serge calderara | last post: by
11 posts views Thread by santosh | last post: by
2 posts views Thread by ricky | last post: by
1 post views Thread by dwaldman | last post: by
3 posts views Thread by Michel Vanderbeke | last post: by
2 posts views Thread by =?Utf-8?B?YmJkb2J1ZGR5?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.