【发布时间】:2011-11-30 18:06:49
【问题描述】:
我需要在遍历 StringBuffer 时获取新行的起始位置。 假设我在字符串缓冲区中有以下文档
"This is a test
Test
Testing Testing"
在“test”、“Test”和“Testing”之后存在新行。
我需要类似的东西:
for(int i =0;i < StringBuffer.capacity(); i++){
if(StringBuffer.chatAt(i) == '\n')
System.out.println("New line at " + i);
}
我知道这行不通,因为 '\n' 不是字符。有任何想法吗? :)
谢谢
【问题讨论】:
-
'\n'是一个字符。 -
它不起作用,因为容量()与长度()不同。请阅读文档!
标签: java stringbuffer