蓝桥杯字符集处理 -字符串

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);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值