其他分享
首页 > 其他分享> > Substring()、lastIndexOf()的用法

Substring()、lastIndexOf()的用法

作者:互联网

lastIndexOf()

例如:

 

string str = "abcdefg";
str = str.Substring(0, str.LastIndexOf("c"));
Response.Write(str);

//结果为 ab    
//就是截取c前面的字符串。

Substring()

例如:

  string qian = null;
    string hou = null;
    string str = "abcdefg";
    qian = str.Substring(0, 1);//从第一个开始截取,共截取一位
    hou = str.Substring(str.Length - 1, 1);//从最后一个开始截取,共截取一位
    Response.Write(qian + "***" + hou);

    //结果为a***g

 

评论人:<%#Eval("userIp").ToString().Substring(0,1)+"***" + Eval("userIp").ToString().Substring(Eval("userIp").ToString().Length - 1, 1)  %>

输出效果:

 

 

 

TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back

标签:lastIndexOf,string,qian,截取,用法,Substring,location,str
来源: https://www.cnblogs.com/lyj0810/p/16341075.html