Hey folks.
Consider i have this QString "EMU 978 EUR 1 7,537897 7,560579 7,583261"
and i need to use the 7,560579 column for further calculations.
any suggestions on how to do it properly?
Printable View
Hey folks.
Consider i have this QString "EMU 978 EUR 1 7,537897 7,560579 7,583261"
and i need to use the 7,560579 column for further calculations.
any suggestions on how to do it properly?
Read about QString::split
thx, that helped. now if i can trouble you some more :D
so i have this parser class im making
Code:
#include <QFile> #include <QTextStream> #include <QString> #include <QTextStream> #include <QMessageBox> #include <QDebug> #include <QStringList> { Q_OBJECT public: int read_line(); void init_map(); void init_list(); private: QMap<QString,float> map; QStringList valute; };
and the .cpp
Code:
#include "parser.h" { init_map(); init_list(); } { QStringList temporary_list; if(line.contains(str,Qt::CaseInsensitive)) this is the part im having trouble with now** { qDebug()<<"found euro"; map.insert("EUR",temporary_list[6].toFloat()); } } int parser::read_line() { if(!file.exists()) { QMessageBox msgBox; msgBox.setText("There is no such file"); msgBox.exec(); return 1; } { QMessageBox msgBox; msgBox.setText("Error while opening file"); return 1; } while (!line.isNull()) { process_line(line); line = in_stream.readLine(); } return 0; } void parser::init_map() { map.insert("AUD",0); map.insert("CAD",0); map.insert("CZK",0); map.insert("DKK",0); map.insert("NOK",0); map.insert("SEK",0); map.insert("CHF",0); map.insert("GBP",0); map.insert("USD",0); map.insert("EUR",0); map.insert("PLN",0); } void parser::init_list() { valute << "AUD" << "CAD" << "CZK" << "DKK" << "NOK" << "SEK" << "CHF" << "GBP" << "USD" << "EUR" << "PLN"; }
i have a txt file of over 60 lines from which i have to read the values.
so i would like my process_line function to check the QString it receives if there is any matching strings from my QStringlist in there.
and if so to insert the value to my map.
im not sure how to write that in my if statement, and im pretty sure also i have the wrong aproach here. so if you could point me in the right direction again, would be very much appreciated.
But what is a problem ?
i dont know how the write the loop.
i did this one with checking only for "EUR" in my line.
to be more precise with some pseudo coding
if(line contains any of the strings from my value QStringList)
split the line into a new qstringlist
instert value from index no.6 to the matching key/value pair in my map
QStringList::contains()
QStringList::indexOf()
Simply :
Code:
{ QStringList str; str << "EUR" << "USD" << "GBP"; for( int i = 0; i < str.size(); i++ ) { if(line.contains(str.at(i),Qt::CaseInsensitive)) { QStringList temporary_list; qDebug()<<"found " << str.at(i); map.insert(str.at(i)",temporary_list[6].toFloat()); } } }