Hi,
I had this function which caused an error, but I want to know why.
It is used to strip strings which may look like this: "text", text, "" or <absolutely nothing>. They originate from a csv file (example line: "text",text,"",)
I kept getting an error when I started processing a second file, which may have completely empty fields (,,,,,)
I found the problem: if I don't use line nr 4 to demand that a string is longer than 1 character before it can be stripped, I get an error.
My question: why is it that it has to be longer than 1 (why isn't length 1 good enough)? I think it must have something to do with '\0', right?
1 2 3 4 5 6 7 8 9 10 11
|
EditedString csvFile::strip(EditedString str_in) //strips the outer characters and removes the inner doubled ones
{
EditedString str = str_in;
if(str.size()>1)
if((str.find('\"')==0) && (str.rfind('\"')==(str.size()-1)))
{
str.erase(0,1);
str.erase(str.size()-1,1); //strip the outer characters
}
return str;
}
|