[Qt-interest] QRexExp to find file in a string

Eric Clark eclark at ara.com
Fri Aug 26 22:55:48 CEST 2011


Is there a reason you are using a regular expression and not just using the QFileInfo and QDir classes? You could always do something like this:

QFileInfo file("/home/dirs/somefile.txt");
QString newFile = file.absoluteDir().absoluteFilePath("newstuff.abc");

This should give you the same result you are looking for.

Thanks,
Eric

> -----Original Message-----
> From: qt-interest-bounces+eclark=ara.com at qt.nokia.com [mailto:qt-
> interest-bounces+eclark=ara.com at qt.nokia.com] On Behalf Of Thiago
> Macieira
> Sent: Friday, August 26, 2011 3:07 PM
> To: qt-interest at qt.nokia.com
> Subject: Re: [Qt-interest] QRexExp to find file in a string
> 
> On Friday, 26 de August de 2011 19:53:08 Cole, Derek wrote:
> > I have a string like
> >
> > /home/dirs/somefile.txt
> >
> > I want to use QRegExp to remove "somefile.txt" and replace it with
> > "newstuff.abc"
> >
> >    QRegExp rx("/w*\\.txt$");
> >
> >     const char *DstFilename =
> > newfile.replace(rx,"newstuff.abc").toStdString().c_str();
> 
> Regardless of whether the replacing works, which object manages the
> lifetime of that pointer?
> 
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>       PGP/GPG: 0x6EF45358; fingerprint:
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358



More information about the Qt-interest-old mailing list