PDA

View Full Version : String Manipulation and string functions



Snaidy
26th August 2016, 04:42
Hi Guyz,
I am new to QT ,I am trying to work with file and manipulate the string from file,I don't know how I can do this,

I have an txt file containing below data,

Target1 :ABCDEF $
Target1 :GHIJ %
Target2 : KLMNO$
Target2 : PQRS%
Target3: TUV
Target4: XYZ

I want to take ABCDEF , GHIJ ,KLMNO , PQRS , TUV , XYZ data alone.

In normal C/C++ ,we use array, string functions and compare .... .I hope in QT also,there is a possibility but I dont know how to take advantage of the pre-defined methods in QT .



for reading file I wrote this,

void MainWindow::readFile()
{
QFile file("/home/renupapa/Desktop/QT/Testfile.txt");

if(!file.open(QFile::ReadOnly|QFile::Text))
{
QMessageBox::warning(this,"Title","Error File not opened !!!!! ");

}
QTextStream in(&file);
QString text=in.readAll();
ui->plainTextEdit->setPlainText(text);
file.close();
}

1. Can any one help me how I can take the specific data from the file and manipulate it ?


2. Also where I can find clear guide on these QT methods with examples ?


Thanks in Advance,
E.Karthick

jefftee
26th August 2016, 07:30
You should first read the docs for QString. It has all of the builtin methods you would expect.

anda_skoa
26th August 2016, 11:49
In normal C/C++ ,we use array, string functions and compare .... .I hope in QT also,there is a possibility but I dont know how to take advantage of the pre-defined methods in QT .

I am not sure what you mean, Qt is a C++ library, whatever C++ code you have will also work when used with code using Qt.



for reading file I wrote this,

Since you have a line oriented file, I would be reading lines and then parsing each line, see jefftee's post and maybe also QRegularExpression.

Cheers,
_