1. String中有两个substring()函数,如下:
  2.  
  3. 一:String.substring(int start)
  4. 参数:
  5. start:要截取位置的索引
  6.  
  7. 返回:
  8. start开始到结束的字符串
  9.  
  10. 例如:String str = "hello word!";
  11. System.out.println(str.substring());
  12. System.out.println(str.substring());
  13.    System.out.println(str.substring());
  14.  
  15. 将得到结果为:
  16. ello word!
  17. lo word!
  18. ord!
  19. 如果start大于字符串的长度将会抛出越界异常;
  20.  
  21. 二:String.substring(int beginIndex, int endIndex)
  22. 参数:
  23.   beginIndex 开始位置索引
  24. endIndex 结束位置索引
  25.  
  26. 返回:
  27. beginIndex位置到endIndex位置内的字符串
  28.  
  29. 例如:String str = "hello word!";
  30. System.out.println(str.substring(,));
  31. System.out.println(str.substring(,));
  32.    System.out.println(str.substring(,));
  33.  
  34. 将得到结果为:
  35. ell
  36. lo
  37. hell
  38.  
  39. 如果startIndexendIndex其中有越界的将会抛出越界异常。

Java SubString截取字符串的更多相关文章

  1. 只显示 前100个字 java 实现截取字符串!使用! <c:if test="${fn:length(onebeans.info)>100 }">${ fn:substri

    博客 文章 只显示 前100个字 java 实现截取字符串!使用! <c:if test="${fn:length(onebeans.info)>100 }">$ ...

  2. golang学习笔记14 golang substring 截取字符串

    golang学习笔记14 golang substring 截取字符串golang 没有java那样的substring函数,但支持直接根据 index 截取字符串mystr := "hel ...

  3. java中截取字符串的方式

    1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len=s.length(); 2.ch ...

  4. C#利用String类的IndexOf、LastIndexOf、Substring截取字符串

    一.String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引(从0开始).搜索从指定字符位置开始,并检查指定 ...

  5. Java中截取字符串中小数点前面的字符

    通过下标获取 String number = "2563.2154"; int index = number.indexOf("."); String intN ...

  6. JS indexOf() lastIndexOf()与substring()截取字符串的区别

    1. String.IndexOf 方法 (value[,startIndex]) value:要查找的 Unicode 字符. 必选项startIndex:搜索起始位置.  可选项 不写从开头查找 ...

  7. 关于Java中截取字符串

    获取系统时间:to_char(sysdate,'yyyy-mm-dd')截取CREATETIME常量的前10位字符串:CREATETIME.substring(0,10)截取DESCRIPT常量的前2 ...

  8. SQL使用UPDATE和SUBSTRING截取字符串方法,从头截取到某个位置,截取中间片段,字符串中间截取到末尾或删除前面的字符串

    //从头截取 update 表名 set 表列名 =SUBSTRING(表列名,1,目标位置数值)  //!计数从1开始,从左往右 where 条件   //条件自己选择,不加where条件会更新所有 ...

  9. substring -----截取字符串

    var str = "0123456789"; substring alert(str.substring(0));------------"0123456789&quo ...

随机推荐

  1. Redis配置文件redis.conf详解

    一.Redis配置文件redis.conf详解 # Note on units: when memory size is needed, it is possible to specifiy # it ...

  2. 小程序 切换到tabBar页面不刷新问题

    小程序跳转的几种方式有wx.navigateTo,wx.redirectTo,wx.reLaunch,wx.switchTab等.下面我们重点研究切换到tabBar的两种方式. wx.switchTa ...

  3. phpstudy如何安装ssl证书

    网站上面部署ssl证书的站点越来越大,但有很多集成式的web服务器无法按照一般站点的配置来部署ssl证书,现在,卓趣科技就以集成式phpstudy为例(apache+mysql),为大家展示一下正确的 ...

  4. ubuntu(centos) server安装vmware tools

    Ubuntu: root登录ubutun $ sudo su vmware中选择菜单虚拟机->安装VMware Tools 命令行如下 // 将cdrom挂载到mnt $ mount -t is ...

  5. CFRunLoop 源码学习笔记(CF-1151.16)

    1.CFRunLoopModeRef 什么时候创建的? 在调用__CFRunLoopFindMode(rl, modeName, create) 1.1)首先通过modeName 在RunLoop 中 ...

  6. ReportViewe调用Reporting Services报表时报错Session超时

    序列化问题加上[Serializable]即可 /// <summary> /// 报表身份授权重写 /// </summary> [Serializable] public ...

  7. ftp权限设置大全!!!

    1.登录和对匿名用户的设置write_enable=YES                         //是否对登录用户开启写权限.属全局性设置.默认NOlocal_enable=YES    ...

  8. js中prototype,constructor的理解

    连看4篇前辈的文章,记录一些知识点 Javascript继承机制的设计思想 Javascript 面向对象编程(一):封装 Javascript面向对象编程(二):构造函数的继承 Javascript ...

  9. C语言实例:函数指针

    函数指针:函数指针数组的使用: 不带参数和返回值的函数指针: #include <stdio.h> #include <stdlib.h> //定义一个没有返回值也没有入口参数 ...

  10. 剑指offer(6)旋转数组中的最小数字

    题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...