java 日常记录

-- 字符串替换忽略大小写

使⽤字符串的replaceAll⽅法,使⽤(?i)匹配符。

例如: (?i)asd,替换asd任何忽略⼤⼩写内容; A(?i)sd,替换 A+(忽略⼤⼩写的sd)。

示例:

String s = "WHERE asd IN ('asd','asd') AND asd <> 0 ";
String s1 = "wHERE asd IN ('asd','asd') AND asd <> 0 ";

System.out.println(s.replaceAll("(?i)where", ""));
asd IN ('asd','asd') AND asd <> 0 

System.out.println(s1.replaceAll("w(?i)here", ""));
asd IN ('asd','asd') AND asd <> 0 

Excel换行  

添加 cellStyle.setWrapText(true);

小串在大串中出现的次数

public static int queryStr(String str , String regex) {
    //计数
    int count;
    //判断是否包含目标字符串
    if (!str.contains(regex)) return 0;
    //以regex分割成为数组,以测试开头能正常,结尾不正常计数
    count = str.split(regex).length-1;
    //以目标字符串结尾,多计数一次
    if (str.endsWith(regex)) count++;
    return count;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值