X
XXX
If I have a string with \r\n & I am trying to convert all \r\n to \n,
then is code like this good enough?
String s // contains the original string.
StringBuffer old = new StringBuffer(s);
StringBuffer new= new StringBuffer();
for (int i=0; i < old.length(); ++i)
{
if (strBuf.charAt(i) != '\r')
{
new.append(old.charAt(i));
}
}
Or are there problems with this? I am think of problems
like
- Is it possible to have strings with just \r not followed by \n.
When can this happen?
- Is it possible for some Unicode chars to have the \r\n pattern
which doesn't represent a new line?
then is code like this good enough?
String s // contains the original string.
StringBuffer old = new StringBuffer(s);
StringBuffer new= new StringBuffer();
for (int i=0; i < old.length(); ++i)
{
if (strBuf.charAt(i) != '\r')
{
new.append(old.charAt(i));
}
}
Or are there problems with this? I am think of problems
like
- Is it possible to have strings with just \r not followed by \n.
When can this happen?
- Is it possible for some Unicode chars to have the \r\n pattern
which doesn't represent a new line?