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

Atlant Schmidt aschmidt at dekaresearch.com
Mon Aug 29 13:08:40 CEST 2011


Eric:

> Is there a reason you are using a regular expression
> and not just using the QFileInfo and QDir classes?

  (I'm not Derek, but...) Probably just TMTOWTDI. In
  any case, both approaches should be workable, no?

                            Atlant



http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it


-----Original Message-----
From: qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com [mailto:qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com] On Behalf Of Eric Clark
Sent: Friday, August 26, 2011 16:56
To: Qt Interest (qt-interest at trolltech.com)
Subject: Re: [Qt-interest] QRexExp to find file in a string

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
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest

This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.



More information about the Qt-interest-old mailing list