Trim leading or trailing characters from a string?

后端 未结 6 1600
鱼传尺愫
鱼传尺愫 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:00

    For those using Spring:

    https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/StringUtils.html#trimTrailingCharacter-java.lang.String-char-

    import org.springframework.util.StringUtils;    
    
    public void setFileName(String fileName) {
        // If the extension does not exist trim the trailing period
        this.fileName = StringUtils.trimTrailingCharacter(fileName,'.');
    }
    

提交回复
热议问题