zoukankan      html  css  js  c++  java
  • 将字符串中间的某段长度替换成固定的值

    今天经理让把手机号的中间几位替换为*,为了保护客户隐私,刚开始一直想着是用字符串的截取啊、替换啊,发现不行,又去查api,看到了

    toCharArray

    public char[] toCharArray()
    将此字符串转换为一个新的字符数组。
    返回:
    一个新分配的字符数组,它的长度是此字符串的长度,它的内容被初始化为包含此字符串表示的字符序列。
    这个方法将字符串转换为字符数组,那就好办了。
                String mobile = (String) map.get("mobile");
                        if(mobile.trim().length()>0 && mobile != null){
                           char[] mobiles = mobile.toCharArray();
                           for(int i =3;i<7;i++){
                               mobiles[i]='*';
                     }
    

      

  • 相关阅读:
    html+css动态篇
    html+css定位篇
    首页的css
    display详细说明
    html+css 布局篇
    html+css杂记
    JS与ES的关系
    H5本地存储
    JavaScript面向对象
    JavaScript执行上下文
  • 原文地址:https://www.cnblogs.com/jjkang/p/8059075.html
Copyright © 2011-2022 走看看