zoukankan      html  css  js  c++  java
  • String

          1.使用String对象存储字符串
         String s="Helloword"
         String s=new String();
         String s=new String("Helloword")

       2.String类位于包java.lang包中,具有丰富的方法
        计算字符串的长度,比较字符串,连接字符串,提取字符串

       3.字符串长度
        语法:方法原理:public int length(){}
        调用方法:字符串标识符.length();
     
       4.字符串比较
        String类提供了equals()方法,比较存储在两个字符对象内容是否一致(返回值boolean类型)
       
        equals与==的区别
         ==:比较是否在同一内存空间或比较数字
         equals:比较内容是否一致

       5.字符串字母转换
        使用equalslgnoerCase()方法--字符串比较时忽略大小写
        使用toLouerCase()方法--返回字符串小写形式
        使用toUpperCase()方法--返回字符串大写形式

      6.字符串连续
        a.使用“+”
        b.使用concat()方法
           A.concat(B);
          B字符串将连续到A字符串后面

      7.字符串提取方法
       a.搜索第一个出现的字符ch(或字符串value)
         public int indexOf(int ch)
         public int indexOf(String value)

       b..搜索最后一个出现的字符ch(或字符串value)
         public int lastindexOf(int ch)
         public int lastindexOf(String value)

       c.从指定位置寻找字符或字符串,返回下标
         s.indexOf(寻找字符.指定位置)

      8.判断字符串是否一指定格式结尾(返回boolean类型)
       s.endsWith(字符串)
        判断字符串是否一指定格式开头(返回boolean类型)
       s.StartsWith(字符串)

      9.常用的提取方法
       a.public string substring(int index)
         提取从位置开始的字符串部分--index
       b.public String substring(int begininelex,int endindex)
         提取begininelex之间的字符串部分
       c.public String trim()
         返回一个前后不含任何空格的调用字符串副本

     10.字符串拆分
      String类提供了Split()方法,将一个字符串分割为子字符串,结果作为字符串数组返回

  • 相关阅读:
    python ascii codec can't decode
    python文件编码说明 coding=utf-8
    windbg的使用
    在后台运行Python脚本服务
    ubuntu下更改分辨率
    【转】VC调试的时候 “没有调试信息,未加载符号”
    常用正则表达式——中文匹配、拉丁匹配
    SQL的经典操作——批量复制同行的其它列数据到其它列数据
    关于C++对汉字拼音的处理(3)
    关于环境变量设置是否需要重启的问题
  • 原文地址:https://www.cnblogs.com/zyani/p/6986138.html
Copyright © 2011-2022 走看看