I don't normally ask for help like this, but I'm having a problem and it's been frustrating me all day.
I'm trying to read in a file, and break up the contents into tokens. There's a lot of whitespace in this file, that I would like to remove (i.e. have it so that no token consists of whitespace). My code looks like this:
I would like my output to be:
route;
16;
blah;
blah;
blah;
(32);
20;
50;
60;
8;
... you get the point.
But instead I get it like:
; <-- shouldn't be here
route;
16;
blah;
blah;
blah;
(32);
20;
50;
60;
; <-- shouldn't be here
8;
...etc
Unfortunately, I'm getting several spaces in, usually at the beginning of a line, with the above code. Any C++ gurus your help is GREATLY appreciated!
I'm trying to read in a file, and break up the contents into tokens. There's a lot of whitespace in this file, that I would like to remove (i.e. have it so that no token consists of whitespace). My code looks like this:
Code:
Regex* r = new Regex("\\n+|\\s+|\\t+"); // Trim Whitespace
StreamReader* sr = new StreamReader(S"file.txt");
try
{
line=sr->ReadLine();
while (!eof) {
for (int l=0; l<split->Length; l++) {
split = r->Split(line);
Console::Write(split[l]);
Console::WriteLine(";");
}
Console::WriteLine("-----");
line=sr->ReadLine();
}
}
and so on...
The file looks similar to this:
route
16 blah blah blah (32)
20 50 60
8 blah blah blah (32)
20 50 60
route;
16;
blah;
blah;
blah;
(32);
20;
50;
60;
8;
... you get the point.
But instead I get it like:
; <-- shouldn't be here
route;
16;
blah;
blah;
blah;
(32);
20;
50;
60;
; <-- shouldn't be here
8;
...etc
Unfortunately, I'm getting several spaces in, usually at the beginning of a line, with the above code. Any C++ gurus your help is GREATLY appreciated!