字符串处理类

      在web开发中,字符串的处理是时常遇见的,而且有些方面的处理是每次都必需的,例如:为空、过滤敏感字符等等,故将这些常用的处理方法封装在一个字符串工具类里是必要的,而且封装为静态方法是比较好的方法。(为了有选择的选用,将每个功能划分为独立的模块)

 

StringUtil.java

public class StringUtil {

 

/判断字符串是否为null----- args.equalsIgnoreCase("null")当向数据库中插入字符串时判断

       public static boolean StringNull(String args){

             

              if(args == null || args.trim().length() == 0 || args.equalsIgnoreCase("null")){

                     return true;

              }else{

                     return false;

              }

       }

 

 

//若源字符串为null或长度为0,target的值赋给源字符串,即给源字符串默认值   

       public static String changeNull(String source,String target){

             

              if(source == null  || source.trim().length() == 0){

                     return target;

              }else{

                     return source;

              }

       }

 

 

 

//过滤敏感字符    

       public static String filterHtml(String input){

              input = input.replaceAll(";", "");

              input = input.replaceAll("&", "&amp");

              input = input.replaceAll("<", "&lt");

              input = input.replaceAll(">", "&gt");

              input = input.replaceAll(" ", "&nbsp");

              input = input.replaceAll("'", "&#39");

              input = input.replaceAll("/"", "&quot");

              input = input.replaceAll("/n", "<br>");

             

              return input;

       }

 

 

}

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值