/** * Delete any character in a given String. * @param inString the original String * @param charsToDelete a set of characters to delete. * E.g. "az\n" will delete 'a's, 'z's and new lines. * @return the resulting String */ public static String
String regEx="[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}[]‘::”“’., .?]"; //可以在中括号内加上任何想要替换的字符,实际上是一个正则表达式 String aa = " ";//这里是将特殊字符换为aa字符串," "代表直接去掉 Pattern p = Pattern.compile(regEx); Matcher m = p
import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author lei * 2011-9-2 */ public class StringUtils { public static String replaceBlank(String str) { String dest = ""; if (str!=null) { Pattern p = Pattern.compile("\\s*|
题目: 比如输入为aaabbc,输出a3b2c1 完整解答: public class Other { static String func(String str) { StringBuffer result = new StringBuffer(); if (str.length() == 1) { result.append(str.charAt(0)); result.append('1'); return result.toString(); } else { // string len
三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar("ddddccffgd")); } public static string removerepeatedchar(string s) { if (s == null) return s; stringbuilder sb = new stringbuilder(); , len = s.