Skipping lines in android java strings
Giveaway Updates - v1.0.0 ------------------------------------- Application has been created---------------------------------------
I checked the application in the emulator. There is exactly 4 dashes in the same line as giveaway updates in which i wanted to only have giveaway updates there. It looks like this ATM
Giveaway Updates - v1.0.0----
-----------------------------
Application has been created-
-----------------------------
how can i make开发者_如何学运维 it so it would be like this?
Giveaway Updates - v1.0.0
-----------------------------
Application has been created
-----------------------------
You can do something like that:
public String changeFormat(String myString) {
String[] lines = myString.split("-[-]+"); // split everytime there are two or more '-'
StringBuffer sb = new StringBuffer(myString.length());
for (String line in lines) {
sb.append(line);
sb.append('\n');
sb.append("-----------------------------");
sb.append('\n');
}
return sb.toString()
}
精彩评论