how to remove the ":" in my .txt file
-
Hi, i'm using qt5.5 on my computer.
I got a string from some website and put in the .txt file which i make.And the string is as below.
MAC1: 00:03:E1:86:42:AB<br>MAC2: 00:03:E1:86:42:AC<br>Model: ADO 7" TERMINAL<br>PN: 752-0005-01<br>SN: 171613020001<br>ESN: 1W1712000001MAC1: 00:03:E1:86:42:AD<br>MAC2: 00:03:E1:86:42:AE<br>Model: ADO 7" TERMINAL<br>PN: 752-0005-01<br>SN: 171613020002<br>ESN: 1W1712000002
I'm gonna only take this "00:03:E1:86:42:AC" for my need.
What could i do ?
Please help! -
Hi, i'm using qt5.5 on my computer.
I got a string from some website and put in the .txt file which i make.And the string is as below.
MAC1: 00:03:E1:86:42:AB<br>MAC2: 00:03:E1:86:42:AC<br>Model: ADO 7" TERMINAL<br>PN: 752-0005-01<br>SN: 171613020001<br>ESN: 1W1712000001MAC1: 00:03:E1:86:42:AD<br>MAC2: 00:03:E1:86:42:AE<br>Model: ADO 7" TERMINAL<br>PN: 752-0005-01<br>SN: 171613020002<br>ESN: 1W1712000002
I'm gonna only take this "00:03:E1:86:42:AC" for my need.
What could i do ?
Please help!@victor-wang You can use a regular expression.
See http://doc.qt.io/qt-5.8/qregularexpression.htmlOne note: the title is misleading. You don't want to remove ":", but extract the MAC address.
-
@victor-wang You can use a regular expression.
See http://doc.qt.io/qt-5.8/qregularexpression.htmlOne note: the title is misleading. You don't want to remove ":", but extract the MAC address.
@jsulm
Thanks for telling me.
And now i got a problem here.
this is my code.if(!file.open(QIODevice::ReadWrite|QIODevice::Text)) { qDebug("No MAC_addr this file"); } else { /*if(MAC2==" ") { QTextStream stream2(&file); stream2<<MAC1;//"MAC1:"+MAC1; } else if(MAC1==" ") { QTextStream stream2(&file); stream2<<MAC2; } else { QTextStream stream2(&file); stream2<<MAC1;//"MAC1:"+MAC1; stream2<<MAC2;//"MAC2:"+MAC2; }*/ QTextStream stream2(&file); stream2<<EIP_out; Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo 5 > /sys/class/gpio/export"); Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo \"out\" > /sys/class/gpio/gpio5/direction"); Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo 0 > /sys/class/gpio/gpio5/value"); if(!weeprom.open(QIODevice::ReadWrite|QIODevice::Text)) { qDebug("No eeprom for first MAC"); } else { QTextStream stream_weeprom(&weeprom); QString tmpString = stream2.readLine(); stream_weeprom<<tmpString; stream_weeprom.seek(43); QString eepromstring = stream_weeprom.readLine(17); qDebug()<<eepromstring; QRegularExpression re("(\\w+)"); QRegularExpressionMatchIterator i = re.globalMatch(eepromstring); while(i.hasNext()) { QRegularExpressionMatch match = i.next(); QString word = match.captured(1); words << word; } qDebug()<<words; stream2<<words; } weeprom.close(); }
I can't do "stream2<<words;" i think it is because i can't write a QStringList in to it.
I don't know how to fix it.
Is there any method can change the type in to QString or char?
Please Help! -
@jsulm
Thanks for telling me.
And now i got a problem here.
this is my code.if(!file.open(QIODevice::ReadWrite|QIODevice::Text)) { qDebug("No MAC_addr this file"); } else { /*if(MAC2==" ") { QTextStream stream2(&file); stream2<<MAC1;//"MAC1:"+MAC1; } else if(MAC1==" ") { QTextStream stream2(&file); stream2<<MAC2; } else { QTextStream stream2(&file); stream2<<MAC1;//"MAC1:"+MAC1; stream2<<MAC2;//"MAC2:"+MAC2; }*/ QTextStream stream2(&file); stream2<<EIP_out; Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo 5 > /sys/class/gpio/export"); Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo \"out\" > /sys/class/gpio/gpio5/direction"); Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/bin/echo 0 > /sys/class/gpio/gpio5/value"); if(!weeprom.open(QIODevice::ReadWrite|QIODevice::Text)) { qDebug("No eeprom for first MAC"); } else { QTextStream stream_weeprom(&weeprom); QString tmpString = stream2.readLine(); stream_weeprom<<tmpString; stream_weeprom.seek(43); QString eepromstring = stream_weeprom.readLine(17); qDebug()<<eepromstring; QRegularExpression re("(\\w+)"); QRegularExpressionMatchIterator i = re.globalMatch(eepromstring); while(i.hasNext()) { QRegularExpressionMatch match = i.next(); QString word = match.captured(1); words << word; } qDebug()<<words; stream2<<words; } weeprom.close(); }
I can't do "stream2<<words;" i think it is because i can't write a QStringList in to it.
I don't know how to fix it.
Is there any method can change the type in to QString or char?
Please Help!@victor-wang You should always mention the error you get.
If it is a QStringList then you can just iterate over it and put each element into stream2. -
Hi,
Or use QStringList::join to do it in one pass.