|
splitting string and replacing
Hi
I am new to JAVA .I am trying to write a code where I have a string which contains several lines.The end character of each line is \n .i want to replace \n with \r\n for my purpose.I need to chk whether each line end with \r\n --if it does do nothing or else replace \n with \r\n.
Below is teh small code i have written but its not working for me .Can any body help?
my string name is is swift
int length =swift.length();
for (int i = 0; i<=length; i++)
int value1 = swift.indexOf("\n");
System.out.println (" value1 is " + value1 );
int value2 = value1 -1;
System.out.println (" value2 is " + value2 );
char mg = swift.charAt(value2);
char pg =swift.charAt (value1);
System.out.println ("Its here now before conversion ");
if ( mg == '\r' )
{ //do nothing
System.out.println (" cntr M is there ");
}
else
{
System.out.println (" Swift message is " + swift );
System.out.println (" Its not there " );
swift.replace("\n","\r\n");
System.out.println (" cntr M was not there and conversion done ");
}
}
|