Say I'm reading a file, line by line, and I want to check if the line QString satisfies any QRegExp I have defined.
I could use a bunch of if statements such as :
while(!in.EOF)
{
line = in.readLine();
if(line.contains(RegExp1)){...}
else if(line.contains(RegExp2){...}
...
else if(line.contains(RegExpN){...}
}
while(!in.EOF)
{
line = in.readLine();
if(line.contains(RegExp1)){...}
else if(line.contains(RegExp2){...}
...
else if(line.contains(RegExpN){...}
}
To copy to clipboard, switch view to plain text mode
But I thought it would be neater to write it in the format of a switch. Can this be done. I've googled, but it gives no relevant results.
I thought I could have done something like this:
while(!in.EOF)
{
switch(true)
{
case line.contains(RegExp1): {...}
...
case line.contains(RegExpN): {...}
}
}
while(!in.EOF)
{
switch(true)
{
case line.contains(RegExp1): {...}
...
case line.contains(RegExpN): {...}
}
}
To copy to clipboard, switch view to plain text mode
Doesn't work though.
Bookmarks