i have written method which takes the big string and breaks into two lines :
private String getNameSplited(String name){
char[] sAr = name.toCharArray();
StringBuffer strBuff = new StringBuffer(name.length());
boolean start = true;
for (int i = 0; i < sAr.length; i++) {
if(i > 20) {
if(sAr[i] == ' ' && start){
strBuff.append("\n");
start = false;
} else {
strBuff.append(sAr[i]);
}
} else {
strBuff.append(sAr[i]);
}
}
return strBuff.toString();
}
In this method "\n" is not working. As in my project we are not using direct System.out.println();
we are using out.print(strBuff); to print this string in a dialog.
So can cany one give suggestion how to make this code work . Thanks you...
\n might not be the newline character in the given system. Use System.getProperty("line.separator") to get the line separator corresponding to the runtime environment.
Use strBuff.append(System.getProperty("line.separator")); Or store System.getProperty("line.separator") as a constant and use it wherever you need a new line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With