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 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