C++ (Qt)QString trimmedStr;...QRegExp rx(trimmedStr);
C++ (Qt)QString trimmedStr;...QRegExp rx("\\b(" + trimmedStr + ")\\b");
C++ (Qt)void MainWindow::bufferButtonSave(){ QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); originalText.replace(QRegExp("\\W"), " "); originalText.replace(QRegExp("\\d"), " "); QTextStream fileStream( & originalText ); QString itemStr, trimmedStr; QList< QString > itemList; QString nnn; text.clear(); do { // Пословно fileStream >>(itemStr); // Построчно// itemStr = fileStream.readLine(); trimmedStr = itemStr.trimmed(); QRegExp rx(trimmedStr); int coun(0); int pos = 0; while ((pos = rx.indexIn(originalText, pos)) != -1) { ++coun; pos += rx.matchedLength(); } nnn.setNum(coun); trimmedStr = trimmedStr + nnn; itemList.prepend( trimmedStr ); } while( !fileStream.atEnd() ); history.enableAdd( true ); for( QList< QString >::const_iterator i = itemList.constBegin(); i != itemList.constEnd(); ++i ) text.addItem( Text::Item( 1, *i ) ); text.enableAdd( cfg.preferences.storeText );}
C++ (Qt)void MainWindow::bufferButtonSave(){ QClipboard *clipboard = QApplication::clipboard(); QString originalText = clipboard->text(); originalText.replace(QRegExp("\\W"), " "); originalText.replace(QRegExp("\\d"), " "); QTextStream fileStream( & originalText ); QString itemStr, trimmedStr; QList< QString > itemList; QString nnn; text.clear(); do { // Пословно fileStream >>(itemStr); // Построчно// itemStr = fileStream.readLine(); trimmedStr = itemStr.trimmed(); QRegExp rx(trimmedStr); int coun(0); int pos = 0; while ((pos = rx.indexIn(originalText, pos)) != -1) { ++coun; ++pos; } nnn.setNum(coun); trimmedStr = trimmedStr + nnn; itemList.prepend( trimmedStr ); } while( !fileStream.atEnd() ); text.enableAdd( true ); for( QList< QString >::const_iterator i = itemList.constBegin(); i != itemList.constEnd(); ++i ) text.addItem( Text::Item( 1, *i ) ); text.enableAdd( cfg.preferences.storeText );}
C++ (Qt)QString src = "This is a text"QMap <QString, int> theMap;QStringList lst = src.split(" ");for (int i = 0; i < lst.size(); ++i) ++theMap[lst[i]];
C++ (Qt)while ((pos = rx.indexIn(originalText, pos)) != -1){ ...}
C++ (Qt)nnn.setNum(coun);if (coun == 40) qDebug() << "opa! " << trimmedStr;
C++ (Qt)for (int i = 0; i < lst.size(); ++i) qDebug() << lst[i] << " " << theMap[lst[i]];