PDA

View Full Version : Can I use QRegExp to remove the extension of a file?



ricardo
20th May 2009, 13:09
Hi mates!

Given a QString (c:\blabla\text.ico) I'd like to remove its extension (c:\blabla\text).
That's pretty easy scaning the string till the dot and splitting it.

My question is, is it possible to use QRegExp to do that?
I ask this cause I read in docs that:
"String Splitting: A regexp can be used to identify where a string should be split apart, e.g. splitting tab-delimited strings."

But no idea about how to do it.

Any idea?

Thanks for your help.

Lykurg
20th May 2009, 13:49
I won't tell you how you can use a reg exp for that, because it is too heavy for a simple operation like that. Better use QString::lastIndexOf() with QString::chop().

nightghost
20th May 2009, 14:15
QFileInfo::absoluteFilePath + QFileInfo::baseName or QFileInfo::completeBaseName could also used

ricardo
20th May 2009, 14:54
Very usefull, thanks a lot! I will use them instead a regular expresion.