String.常用的属性方法

来源:互联网 发布:seo 内链 外链 编辑:程序博客网 时间:2024/05/22 10:34
String.ToLower() 方法: 返回此 String 的小写形式的副本。
String.ToUpper() 方法: 返回此 String 的大写形式的副本。
String.TrimEnd() 方法: 从此实例的末尾移除一组指定字符的所有匹配项。。
String.TrimStart() 方法: 从此实例的开始位置移除一组指定字符的所有匹配项。。
String.Trim () 方法: 从此实例的开始位置和末尾移除一组指定字符的所有匹配项。。
 
 
String.StartsWith 属性 确定此实例的开始处是否与指定的 String 匹配。
String.EndsWith 属性 确定此实例的末尾是否与指定的 String 匹配。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = (Label1.Text.EndsWith(".exe")).ToString();
   Label3.Text = "asdfasdfasdfexe";
   Label4.Text = (Label3.Text.EndsWith(".exe")).ToString();
String.Length 属性 获取此实例中的字符数。  
String.IndexOf 属性 在此实例中的第一个匹配项的索引或一个或多个字符的索引。
String.IndexOfAny 属性 报告指定 Unicode 字符数组中的任意字符在此实例中第一个匹配项的索引。
String.LastIndexOfAny  属性 报告在 Unicode 数组中指定的一个或多个字符在此实例中的最后一个匹配项的索引位置。
String.LastIndexOf 指定的 Unicode 字符或 String 在此实例中的最后一个匹配项的索引位置。
   Label1.Text = "asd.fasdf.exe";
   Label2.Text = (Label1.Text.LastIndexOf(".")).ToString();
  
 
String.Substring(int开始位置,int长度) 方法 从此实例检索子字符串。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = Label1.Text.Substring(Label1.Text.LastIndexOf("."),(Label1.Text.Length-Label1.Text.LastIndexOf("."))).ToString();
  
String.Replace 将此实例中的指定 Unicode 字符或 String 的所有匹配项替换为其他指定的 Unicode 字符或 String。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = Label1.Text.Replace("asd","XXX");
String.Remove 方法 从此实例中的指定位置开始删除指定数目的字符。
   string.Remove(int 开始删除字符的位置,int 要删除的字符数);
   Label1.Text = "asdfasdfa asdf adf asdf asdf asdf asdf asdf asdf asdf asdf .exe";
   Label2.Text = Label1.Text.Remove(15,Label1.Text.Length-15)+"...";
 
原创粉丝点击