CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

怎么样得到一个字符串的后面几个字符?

楼主jighrfgdd()2005-08-03 11:36:13 在 Java / Web 开发 提问

怎么样得到一个字符串的后面几个字符? 问题点数:100、回复次数:7Top

1 楼linus_lee(会游泳的鱼)回复于 2005-08-03 11:39:05 得分 0

subString(str,m,str.length)Top

2 楼shenpipi(皮皮)回复于 2005-08-03 11:39:37 得分 0

要是想要后面的几个字符组成的字符串用,subString,要单个的字符,用charAtTop

3 楼rower203(华仔)回复于 2005-08-03 11:43:44 得分 0

String   str   =   "adfasdf";  
          int   n   =   3;  
          System.out.println(str.substring(str.length()   -   n));Top

4 楼masse(当午 http://blog.sina.com.cn/xukf)回复于 2005-08-03 11:44:06 得分 0

String   src   =   "abchehehehe";  
  String   s   =   "abc";  
   
  //   得到src中“abc”之后的所有字符串  
  String   result   =   src.substring(src.indexOf(s)+s.length);//   hehehehe  
   
  //   得到src中“abc”之后的长度为4的字符串  
   
  String   result   =   src.substring(src.indexOf(s)+s.length   ,   src.indexOf(s)+s.length   +   4);   //hehe  
  Top

5 楼masse(当午 http://blog.sina.com.cn/xukf)回复于 2005-08-03 11:45:41 得分 0

String   src   =   "abchehehehe";  
  String   s   =   "abc";  
  int   index   =   src.indexOf(s)+s.length;   //   "abc"后的位置  
   
  //   得到src中“abc”之后的所有字符串  
  String   result   =   src.substring(index);//   hehehehe  
   
  //   得到src中“abc”之后的长度为4的字符串  
  String   result1   =   src.substring(index,index+4);   //heheTop

6 楼interhanchi(on the Java Road)回复于 2005-08-03 12:00:03 得分 0

1  
  substring  
  public   String   substring(int   beginIndex)  
  Returns   a   new   string   that   is   a   substring   of   this   string.   The   substring   begins   with   the   character   at   the   specified   index   and   extends   to   the   end   of   this   string.    
  Examples:    
   
    "unhappy".substring(2)   returns   "happy"  
    "Harbison".substring(3)   returns   "bison"  
    "emptiness".substring(9)   returns   ""   (an   empty   string)  
     
   
  Parameters:  
  beginIndex   -   the   beginning   index,   inclusive.    
  Returns:  
  the   specified   substring.    
  Throws:    
  IndexOutOfBoundsException   -   if   beginIndex   is   negative   or   larger   than   the   length   of   this   String   object.  
   
  2  
  substring  
  public   String   substring(int   beginIndex,  
                                                  int   endIndex)  
  Returns   a   new   string   that   is   a   substring   of   this   string.   The   substring   begins   at   the   specified   beginIndex   and   extends   to   the   character   at   index   endIndex   -   1.   Thus   the   length   of   the   substring   is   endIndex-beginIndex.    
   
  Examples:    
   
    "hamburger".substring(4,   8)   returns   "urge"  
    "smiles".substring(1,   5)   returns   "mile"  
     
   
  Parameters:  
  beginIndex   -   the   beginning   index,   inclusive.  
  endIndex   -   the   ending   index,   exclusive.    
  Returns:  
  the   specified   substring.    
  Throws:    
  IndexOutOfBoundsException   -   if   the   beginIndex   is   negative,   or   endIndex   is   larger   than   the   length   of   this   String   object,   or   beginIndex   is   larger   than   endIndex.  
  Top

7 楼laughsmile(海边的星空)回复于 2005-08-03 12:51:48 得分 0

public   String   last(String   str,int   count){  
          if(str   ==   null)  
                  return   null;  
          if(count   <=   0)        
                  return   null;  
          if(str.length()<=count)  
                  return   str;  
          return   str.substring(str.length()-count);  
  }  
  Top

相关问题

  • 怎么样用循环得到带数字的字符串啊
  • 怎么样把UNICODE 字符串转化成 ANSI 字符串
  • 怎么样取一个字符串的取子字符串??
  • 怎么样用JavaScript得到一个字符串的前几个字符?
  • 请问怎么样连接字符串?
  • 怎么样加密字符串啊?
  • 怎么样比较字符串呢?
  • 怎么样快速拼合字符串
  • 怎么样执行字符串??
  • 字符串.....哎,字符串

关键词

  • 字符
  • 字符串
  • substring
  • src
  • 得到
  • abc
  • indexof
  • length
  • str
  • result

得分解答快速导航

  • 帖主:jighrfgdd

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo