Hello,
I'd like to remove ends of line from the string. I've tried:
static final Pattern END_LINE_PATTERN = Pattern.compile("$+");
strBuf.append(input);
Matcher m = END_LINE_PATTERN.matcher(input);
int startIndex = -1;
int endIndex;
while (m.find()) {
startIndex = m.start();
endIndex = m.end();
if (endIndex == strBuf.length() - 1) break;
}
if (startIndex > -1) {
strBuf.setLength(startIndex);
}
For strings "hello\n" and "hello\r" it works properly, but for string "hello\n\n" I get first occurrence at index 6 (at second \n), so as the result I get "hello\n". For the string "hello\r\n" I get first occurrence at index 5 (it's OK), but the end index is 5 as well, and the next occurrence I get at index 7, which doesn't give me any sense.
Hope somebody can help me.
Agata