16,227
社区成员
发帖
与我相关
我的任务
分享
QString modifyText(const QString &str){
static int wraplen = 54;
QString result = str;
int index = result.indexOf(" ");
int preIndex = 0, startIndex = 0;
int length;
while (index > 0){
length = index - startIndex;
if (length > wraplen){
result[preIndex]='\n';
startIndex = preIndex + 1;
length = 0;
}
preIndex = index;
index = result.indexOf(" ", index + 1);
}
return result;
}
QString modifyText(const QString &str){
static int wraplen = 54;
QString tmp = str;
QString result;
int strLen = tmp.length();
if (strLen <= wraplen)
return tmp;
QStringList list = tmp.split(" ");
QString line;
for (int i = 0; i < list.count(); i++){
if ((line.length() + list[i].length()) > wraplen){
result += line + "\n";
line.clear();
}
line += list[i] + " ";
}
if (!line.isEmpty())
result += line;
return result;
}