Home  >  Article  >  php教程  >  Remove the last comma from the String attribute

Remove the last comma from the String attribute

大家讲道理
大家讲道理Original
2016-11-09 10:24:231367browse

It can also be other symbols. When you have this kind of problem, you should consider changing the storage location first (you can split it into arrays according to the specified string, and only add delimiters when the length is greater than 1, otherwise there is no need to add it at the end)

Boolean isNotEmpty = StringUtils.isNotBlank(this.version);
Boolean lastIndex = false;
if(isNotEmpty){
    lastIndex = ",".equals(this.version.substring(version.length()-1));
}
 
if(isNotEmpty && lastIndex){
    return this.version.substring(0,version.length()-1);
}else{
    return this.version;
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn