蓝桥杯字符集处理 -字符串
程序员文章站
2022-05-16 08:44:49
...
import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Title { public static void main(String[] args){ f(); } public static void f(){ String newStr = ""; String message="you dd me want money20009program3225iuoiu89453ty67s"; String[] s = message.split(" "); for(int i=0;i<s.length;i++){ String temp = s[i]; if(s[i].equals("")){ continue; } //数字字母问题 Pattern p = Pattern.compile("[a-z]\\d{1}"); Pattern p2 = Pattern.compile("\\d[a-z]{1}"); Matcher m = p.matcher(temp); Matcher m2 = p2.matcher(temp); //str_是切出来的字段 ArrayList<String> str_= new ArrayList<String>(); boolean isS = false; while(m.find()&&m2.find()){ System.out.println(m.group()); System.out.println(m2.group()); str_.add(m.group()); str_.add(m2.group()); isS = true; } //拆分 if(isS){ System.out.println("开始拆分数据"); String tempStr1 =""; String tempStr2 =""; for(int h=0;h<str_.size();h++){ String a = str_.get(h); //临时存储组里面的字段 for(int k=2;k<temp.length();k++){ System.out.println("此时组里面取出来的是:"+a); System.out.println("截取:"+temp.substring(k-1,k+1)); if(temp.substring(k-1,k+1).equals(a)){ //在字符中找到了 指定的组 System.out.println("测试"); System.out.println("前段的值:"+temp.substring(0,k)+"_"); System.out.println("后段值:"+temp.substring(k)); tempStr1 = temp.substring(0,k)+"_"; //前段 tempStr2 = temp.substring(k); temp=tempStr1+tempStr2; //后段字符 break; } } } //组合新的字段 s[i] = temp; } //转换字符 s[i] = s[i].replaceFirst(temp.substring(0,1), temp.substring(0,1).toUpperCase()); newStr = newStr +s[i]+" "; } System.out.println(newStr); } }