2012-12-02 120 views
2

我需要将qstring拆分为两个字符串,但只知道拆分器字符的索引。这里有一个的exaple拆分QString与拆分索引

input: 
PineApple 
3 

Output: 
Pine // 'e' has index 3, so it is the splitter char and it belongs to the first part 
Apple 

回答

5

如果我正确理解你的问题,你可以使用leftmid方法之前和之后的offset提取字符串的部分:如果你正在寻找

quint32 offset = 4; 
QString test("PineApple"); 
QString before = test.left(offset); // Pine 
QString after = test.mid(offset); // Apple 

QStringList结尾(如果您使用的是split,那么您可以得到如下结果):

QStringList list; 
list << before 
    << after;