Problem replacing "

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I have a string which is as follows:

"simon"

I want to replace/remove the " with a space, so it will give me the following:

simon

However I am having a problem putting the " in the replace function, see code below which gives error:

VB.NET:
line = replace(line,""","")

I am using VB.Net

Thanks in advance

Simon
 
You have to use 2 " to denote one when you code quoted string because the " char is already used as data delimiter for the String data type.
VB.NET:
Dim hello As String = "It is easier to ""see"" this logic than to explain it."
In your case you could easily use this way to write quoted quote char, if you were writing a string literal like the example code this would be preferred, but you could also here use the constant ControlChars.Quote which will make the code more readable:
VB.NET:
line = line.Replace(ControlChars.Quote, String.Empty)
 
Thank you that worked, I do however have another probelm.

I am trying to read a CSV file and splitting it into the relavent columns, however I have a problem when splitting the lines.

e.g. simon, simon, simon

This gives me:

simon
simon
simon

Splits fine and I get three columns, however when I have the following line I have a problem splitting it correctly:

e.g. simon,"simon,1",simon

The words inbetween the " should not be split, therefore giving me:

simon
simon,1
simon

However I do not know how to acheive this, any help would be appreshiated.

I know that there are better way of doing this instead of using string manipulation however I need to perform a number of checks on the content of the CSV that it conforms to certain format criteria of my application and that certains columns that are required are not missing

Thanks in advance

Simon
 
see this post about how to insert a code snippet to read delimited files, and you don't have write a parser class yourself.
 
Thank you so much JohnH, that has saved me no end of coding, never know that was possible, will definately look into the insert code

Cheers

Simon
 
Back
Top