Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to remove the ":" in my .txt file
QtWS25 Last Chance

how to remove the ":" in my .txt file

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    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:&nbsp;00:03:E1:86:42:AB<br>MAC2:&nbsp;00:03:E1:86:42:AC<br>Model:&nbsp;ADO 7" TERMINAL<br>PN:&nbsp;752-0005-01<br>SN:&nbsp;171613020001<br>ESN:&nbsp;1W1712000001MAC1:&nbsp;00:03:E1:86:42:AD<br>MAC2:&nbsp;00:03:E1:86:42:AE<br>Model:&nbsp;ADO 7" TERMINAL<br>PN:&nbsp;752-0005-01<br>SN:&nbsp;171613020002<br>ESN:&nbsp;1W1712000002
    

    I'm gonna only take this "00:03:E1:86:42:AC" for my need.
    What could i do ?
    Please help!

    jsulmJ 1 Reply Last reply
    0
    • V victor wang

      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:&nbsp;00:03:E1:86:42:AB<br>MAC2:&nbsp;00:03:E1:86:42:AC<br>Model:&nbsp;ADO 7" TERMINAL<br>PN:&nbsp;752-0005-01<br>SN:&nbsp;171613020001<br>ESN:&nbsp;1W1712000001MAC1:&nbsp;00:03:E1:86:42:AD<br>MAC2:&nbsp;00:03:E1:86:42:AE<br>Model:&nbsp;ADO 7" TERMINAL<br>PN:&nbsp;752-0005-01<br>SN:&nbsp;171613020002<br>ESN:&nbsp;1W1712000002
      

      I'm gonna only take this "00:03:E1:86:42:AC" for my need.
      What could i do ?
      Please help!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @victor-wang You can use a regular expression.
      See http://doc.qt.io/qt-5.8/qregularexpression.html

      One note: the title is misleading. You don't want to remove ":", but extract the MAC address.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      2
      • jsulmJ jsulm

        @victor-wang You can use a regular expression.
        See http://doc.qt.io/qt-5.8/qregularexpression.html

        One note: the title is misleading. You don't want to remove ":", but extract the MAC address.

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @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!

        jsulmJ 1 Reply Last reply
        0
        • V victor wang

          @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!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Or use QStringList::join to do it in one pass.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              or use a more meaningful regexp like
              QRegularExpression regexp("MAC\\d+:.+?;([0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2})"); and use the cap(1) to retrieve the mac address

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved