Delete all punctuations of a string
str = str.replaceAll("[//pP''"]", "");Unicode encoding is used here. Unicode encoding does not simply define an encoding for a character, but also classifies it.
/pP where lowercase p means property, which means Unicode attribute, and is used for the prefix of Unicode regular expressions.
Capital P means one of the seven character attributes of the Unicode character set: punctuation characters.
The other six are
Regular expression data for Unicode in Java are provided by Unicode organizations. Unicode regular expression standard (all sub-properties can be found)
http://www.unicode.org/reports/tr18/
http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
One line of this text document is a character, the first column is Unicode encoding, the second column is a character name, and the third column is a Unicode attribute.
and some other character information.
Delete the last character of the string
String:
string s = "1,2,3,4,"
Implement the effect: delete the last ","
method:
1. Use Substring
s = s.Substring(0,s.Length - 1)
2. Use RTrim
s = s.ToString().RTrim(',')3. Use TrimEnd
s=s.TrimEnd(',')//If you want to delete "4,", you need to write char[] MyChar = {'4',','};s = s.TrimEnd(MyChar);// s = "1,2,3 4. Use lastIndexOf() and deleteCharAt()
int index = sb.toString().lastIndexOf(',');sb.deleteCharAt(index);