Trim leading or trailing characters from a string?

后端 未结 6 1607
鱼传尺愫
鱼传尺愫 2020-11-27 21:19

How can I trim the leading or trailing characters from a string in java?

For example, the slash character \"/\" - I\'m not interested in spaces, and am looking to t

6条回答
  •  难免孤独
    2020-11-27 22:07

    You could use

    Leading:

    System.out.println("//test/me".replaceAll("^/+", ""));
    

    Trailing:

    System.out.println("//test/me//".replaceAll("/+$", ""));
    

提交回复
热议问题