`
zhangyaochun
  • 浏览: 2560980 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

String的lastIndexOf

阅读更多

 

  lastIndexOf  

 

    ---------  返回一个指定的字符串最后出现的位置,在一个字符串的指定位置从后向前搜索。

 

 

/*
@searchvalue 必需。需检索的字符串值
@fromindex 可选的整数参数,规定在字符串中开始检索的位置
   合法取值0 到 stringObject.length-1,如果缺省的话,就是从字符串的最后一个字符开始检索
*/
stringObject.lastIndexOf(searchvalue,fromIndex);

 

注释

 

  • lastIndexOf对大小写敏感
  • 如果没有检索到指定的字符,返回-1
  • 返回的值也是和indexOf一样的
"zhangyaochun".lastIndexOf("z");   //0
"zhangyaochun".lastIndexOf("z");   //0

 

 
 
扩展阅读:
 
 
分享到:
评论

相关推荐

    C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    JavaScript中的lastIndexOf()方法使用详解

    string.lastIndexOf(searchValue[, fromIndex]) 下面是参数的详细信息: searchValue : 一个字符串,表示要搜索的值 fromIndex : 在调用字符串内的位置,从开始搜索。它是介于0-字符串的长度任意整数。缺省值是0...

    StringAPI.java

    int lastIndexOf(String str, int fromIndex):返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索 boolean endsWith(String suffix):测试此字符串是否以指定的后缀结束 boolean ...

    详解JavaScript中数组和字符串的lastIndexOf()方法使用

    Array.prototype.lastIndexOf 和 String.prototype.lastIndexOf 是非常的实用的方法,不过很多人不知道它其实可以传递两个参数,第二个参数决定了搜索的起始位置: 语法 str.lastIndexOf(searchValue[, fromIndex]...

    JavaScript程序设计课件:String对象.pptx

    lastIndexOf(searchValue) 方法 获取searchValue在字符串中最后出现的位置 substring(start[, end]) 方法 截取从start位置到end位置之间的一个子字符串 substr(start[, length]) 方法 截取从start位置开始到length...

    C# WinForm 文件上传下载

    string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf("\\") + 1); NewFileName = DateTime.Now.ToString("yyMMddhhmmss") + DateTime.Now.Millisecond.ToString() + fileNamePath.Substring...

    Java String类常用的方法.docx

    int indexOf(int ch):返回指定字符ch在此字符串中第一次出现的位置。 int indexOf(String str):返回指定字符串str在此字符串中第...int lastIndexOf(String str):返回指定子字符串str在此字符串中最后一次出现的位置。

    StringJS:Swift中JavaScript字符串API

    StringJS Swift扩展库 一个很小的Swift扩展库,实现了我们惯用JavaScript String函数。... lastIndexOf(string: String) -> Int? match(pattern:String) -> Array<String>? replace(what:String, w

    String方法与IO流小结

    String 1.基础方法 int length(); 获取字符串长度 “” 1.char charAt(int index); 获取指定下标位置的元素 2.int indexOf(char ch); 找出指定元素的下标 3.int indexOf(String str);...int lastIndexOf(String str);

    string-array:字符串数组类

    撤销() 种类() 拼接() 存取方法指数() lastIndexOf() 片() 连接() 加入() toString() toLocaleString() toArray() 迭代方法forEach() 每一个() 一些() 筛选() 地图() 减少() 减少右() ...

    PowerShell String对象方法小结

    默认文本存储在String对象中,它包含了许多非常有用的处理文本的命令。例如,要确定一个文件的扩展名,可以使用LastIndexOf()获取最后一个字符“.”的位置,继续使用Substring()获取扩展名子串。 PS> $path = C:\...

    javascript函数大全

    变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算) 97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置. 98.string.match(regExpression),判断字符是否匹配. 99.string....

    文件批量转格式器械

    string filename1 = fileName.Substring(fileName.LastIndexOf("\\") + 1, fileName.Length - fileName.LastIndexOf("\\") - 5); //设定字符串选择的长度; listBox1.Items.Add(fileName); string a = "C:\\...

    treeview 的用法?

    string mypic = mystr.Substring(mystr.LastIndexOf("\\") + 1); string myspilt=mypic.Substring(mypic.LastIndexOf('.')+1).ToLower(); if (myspilt == "jpg" || myspilt == "gif" || myspilt == "bmp") ...

    java uploadify完整图片批量上传带返回路径

    File targetFile=null;//新文件对象 File findNameFile=... int idx=fullname.lastIndexOf("."); String suffix=fullname.substring(idx);//文件后缀 String name=fullname.substring(0,idx);//文件名字

    检查字符串的合法性

    string fileType = strFileName.Substring(strFileName.LastIndexOf(".") + 1).ToLower(); if (fileType == "gif" || fileType == "jpeg" || fileType == "png" || fileType == "jpg" || fileType == "bmp") { ...

    关于模块代码

    string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath("images/") + filename; //string serverpath = @"d:/" + filename; FileUpload1.PostedFile.SaveAs...

    复杂邮件程序完整Java源码,支持添加附件,图片,HTML格式文本,支持远程WebService调用

    void sendMail(String sender,String password,String addressee,String subject,String text,Map<String,File> enclosures,Map<String,RecipientType> copyToSends) throws Exception; /** * sendMail 发送...

    android的启动方式

    public List<String> getPictures(final String strPath) { List<String> list = new ArrayList<String>();... int idx = f.getPath().lastIndexOf("."); if (idx ) { continue; }

Global site tag (gtag.js) - Google Analytics