Qt中QString中提供两种简单易行的分隔字符串的函数,section和split
1.QString seciton
QString::section提供了四种重载函数,如下:
QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const
QString section(const QString & sep, int start, int end = -1, SectionFlags flags = SectionDefault) const
QString section(const QRegExp & reg, int start, int end = -1, SectionFlags flags = SectionDefault) const
QString section(const QRegularExpression & re, int start, int end = -1, SectionFlags flags = SectionDefault) const
section入口的第一个参数为分隔判定符(字符,字符串,正则表达式),start为起始位置,end为结束位置,最后一个为sectionFlag.开始和结束位置不是附属,从左边开始计数,为0,1,2···,如果是负数就从右边开始计数,为-1,-2,···,end没有设置时,默认到字符串结束位置。
Qchar:
QString test("one,two,three,four,five");
test=test.section(',&