答案 0 :(得分:1)
您的substr()
功能出了问题。添加了一些调试变量,并使用2个不同的字符串运行。这是每个的第一次迭代:
while(result.length() < Width)
{
i = result.nextBlank(i);
String temp1 = result.substr(0,i);
String temp2 = " ";
String temp3 = result.substr(i + 1, result.length());
int tmpint = result.length();
result = result.substr(0,i) + " " +result.substr(i + 1, result.length());
i = result.nextNonBlank(i);
}
i: 1 tmpint: 34 result: 0x603450 "A string without a beginning space" tmp1: 0x6038b0 " with beginning space\021\001A " tmp2: 0x603670 " " tmp3: 0x603ad0 "x¦[÷ÿ\177string without a beginning space" i: 0 tmpint: 24 result: 0x603450 " with beginning space" tmp1: 0x6038b0 "x¦[÷ÿ\177x¦[÷ÿ\177x¦[÷ÿ\177x¦[÷ÿ\177\021\001 " tmp2: 0x603690 " " tmp3: 0x603ad0 " with beginning space"