开发者

Skipping lines in android java strings

开发者 https://www.devze.com 2023-03-18 21:12 出处:网络
Giveaway Updates - v1.0.0------------------------------------- Application has been created---------------------------------------
  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()
}
0

精彩评论

暂无评论...
验证码 换一张
取 消