我需要将qstring拆分为两个字符串,但只知道拆分器charachter的索引.这是一个例子
input:
PineApple
3
Output:
Pine // 'e' has index 3, so it is the splitter char and it belongs to the first part
Apple
Run Code Online (Sandbox Code Playgroud)
如果我正确理解你的问题,你可以使用left和mid方法在一个之前和之后提取字符串的部分offset:
quint32 offset = 4;
QString test("PineApple");
QString before = test.left(offset); // Pine
QString after = test.mid(offset); // Apple
Run Code Online (Sandbox Code Playgroud)
如果您希望最终获得QStringList(如果您使用过的话split),您可以获得如下所示:
QStringList list;
list << before
<< after;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3572 次 |
| 最近记录: |