• 《Java从入门到精通(入土)》字符串 中


    • 字符串操作

      1.获取子字符串

      格式:str.substring(int index);

         str.substring(beginIndex,endIndex);

      2.去除空格

        trim()方法去除前导空格和尾部空格。

        格式:str.trim();

      

      

      3.字符串替换

      格式:str.replace(oldchar,newchar);

      

      

      4.判断字符串的开始和结尾

      格式:str.startsWith(String prefix);

        str.endsWith(String prefix);

        ps:返回是boolean值

      5.判断字符串是否相等

        不能直接用==,这样比较的是比较两个字符串地址是否相同。

        格式:str.equals(string otherstr);

           str.equalsIgnoreCase(string otherstr);//忽略大小写比较相等

        

      6.按字典顺序比较两个字符串

      格式:str.compareTo(String otherstr);

      按字典顺序String对象在参数字符串前,返回-1;string对象在参数字符串之后返回1;相等返回0。

      

      7.字母大小写转换

      格式:str.toLowerCase();//转换成小写

            str.toUpperCase();//转换成大写

        

      

      8.字符串分割 

        格式:str.split(string sign);

           str.split(sign,limit);//limit是分割次数

      

  • 相关阅读:
    TypeError: Buffer.alloc is not a function
    node.js服务端程序在Linux上持久运行
    C#中的反射
    群要事日记
    vs2017 自定义生成规则 错误 MSB3721 命令 ”已退出,返回代码为 1。
    VP9 Video Codec
    用户手册是Yasm汇编
    更改Mysql数据库存储位置
    注册表项
    C#开发可以可视化操作的windows服务
  • 原文地址:https://www.cnblogs.com/xzzheng/p/11070952.html
Copyright © 2020-2023  润新知