I'd do:
Qt Code:
  1. float extractCmd(const QString &str, const QString &expected){
  2. if(expected.size()>2 || str.size()<4) return 0;
  3. QStringList commands = str.simplified().split(",");
  4. static QRegExp rx("([A-Z][A-Z])#([0-9]*\\.?[0-9]+)");
  5. foreach(QString cmd, commands){
  6. if(!rx.exactMatch(cmd))
  7. continue;
  8. if(rx.cap(1)==expected)
  9. return rx.cap(2).toFloat();
  10. }
  11. }
  12.  
  13. QString str = "DV#1200.03,AB#34,SH#100\r\n\0";
  14. float val = extractCmd(str, "SH");
To copy to clipboard, switch view to plain text mode