[Qt-interest] Text file manipulation
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Sat Oct 31 08:02:05 CET 2009
Use a regular expression QRegExp
You can replace one at a time, or multiple at once...
Scott
-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Phil
Sent: Friday, October 30, 2009 11:53 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Text file manipulation
Thank you for reading this.
The following is a simplified version of what I'm trying to achieve.
I have a text file that looks something like this:
fruit, apple, orange, grape
fruit, lemon, quince, pear
vegetable, turnip, pea, onion
The first thing I have done is to read the text file into a QStringList
which gives me one long comma separated string.
Then, say I'm looking for fruit.
I search though the QStringList and place each occurrence of fruit
into a table like this which I display:
apple orange grape
lemon quince pear
So far so good.
Now say I want to change quince to cherry and then save the
original text file with the changed text. This where things get
messy.
I've had to keep a counter of where quince occurred in the
QStringList and replace it with cherry at that index point. It sounds
simple enough but the code has turned out to be quite complicated
and I think there must be a far simpler alternative.
I was thinking along the lines of a two-dimensional QStringList or
QByteArray but achieving either is not obvious to me at the
moment either.
I've spent most of the day on this, can anyone offer any
suggestions?
--
Regards,
Phil
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list