Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QStringList QString::split ( const QString sep,
SplitBehavior  behavior = KeepEmptyParts,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const

Splits the string into substrings wherever sep occurs, and returns the list of those strings. If sep does not match anywhere in the string, split() returns a single-element list containing this string.

If cs is true, the string is only split only where characters are found that match sep exactly. If cs is false, the string is split, the string is split where characters are found that match sep case insensitively (e.g. "and" matches "AND").

If behavior is QString::SkipEmptyParts, empty entries don't appear in the result. By default, empty entries are kept.

Example:

        QString str = "a,,b,c";
        QStringList list1 = str.split(",");
        // list1: [ "a", "", "b", "c" ]

        QStringList list2 = str.split(",", QString::SkipEmptyParts);
        // list2: [ "a", "b", "c" ]

See also:
QStringList::join(), section()

Definition at line 5237 of file qstring.cpp.

References QList< T >::append(), end(), indexOf(), mid(), and size().

Referenced by QHostInfo::fromName(), QKeySequence::fromString(), QFont::fromString(), QDirModel::index(), QLibrary::isLibrary(), QMetaEnum::keysToValue(), QHostInfo::lookupHost(), Q3MainWindow::operator>>(), Q3TextEdit::optimAppend(), Q3TextEdit::optimInsert(), Q3TextEdit::optimSetText(), Q3ListViewItem::paintCell(), QHttpHeader::parse(), QHttpRequestHeader::parseLine(), QDir::relativeFilePath(), Q3TextEdit::scrollToAnchor(), section(), and QFileDialog::selectedFiles().

{
    QStringList list;
    int start = 0;
    int extra = 0;
    int end;
    while ((end = indexOf(sep, start + extra, cs)) != -1) {
        if (start != end || behavior == KeepEmptyParts)
            list.append(mid(start, end - start));
        start = end + sep.size();
        extra = (sep.size() == 0 ? 1 : 0);
    }
    if (start != size() || behavior == KeepEmptyParts)
        list.append(mid(start));
    return list;
}


Generated by  Doxygen 1.6.0   Back to index