Please use [
code] tags.
re: FileConverter -- why wait? Remove it now. Code is easiest to follow when decluttered.
I don't know what "the_string" is, but you should be messing directly with "input_sz":
1 2 3 4 5 6
|
result = input_sz.find( "," );
while ( result != string::npos )
{
input_sz[ result ] = '*';
result = input_sz.find( ",", result );
}
|
This has the caveat that your input cannot ever have a
'*' in it. Are you sure that it doesn't?
You might be better off just
find()ing the pipes
'|' and splitting the string out from that
(using
substr( previous_result + 1, result - previous_result - 1 )
).
Once you have split the substring out, you can simply check to see if it has any characters that need quoting. If it does, add double-quotes to the ends of the string.
1 2 3 4
|
if (the_substring.find( "," ) != string::npos)
{
the_substring = '"' + the_substring + '"';
}
|
All this substring stuff can be made easier by using an
istringstream and another loop with
getline(), this time stopping at a pipe instead of a newline:
1 2 3 4 5
|
istringstream ss( input_sz );
while (getline( ss, the_substring, '|' ))
{
...
}
|
In any case, there is still one possible caveat. Is it possible that your input has quoted fields? Stuff like:
hello|"world|everyone"|""""
which is three fields:
hello
world|everyone
"
If it does, then you'll need to adjust your reading approach.