Java String类属性方法整理

来源:互联网 发布:淘宝佰草集官方旗舰店 编辑:程序博客网 时间:2024/05/22 14:38

String.常用的属性方法

1、String.ToLower() 方法: 返回此 String 的小写形式的副本。
2、String.ToUpper() 方法: 返回此 String 的大写形式的副本。
3、String.TrimEnd() 方法: 从此实例的末尾移除一组指定字符的所有匹配项。
4、String.TrimStart() 方法: 从此实例的开始位置移除一组指定字符的所有匹配项。
5、String.Trim () 方法: 从此实例的开始位置和末尾移除一组指定字符的所有匹配项。

6、String.StartsWith 属性 确定此实例的开始处是否与指定的 String 匹配。
7、String.EndsWith 属性 确定此实例的末尾是否与指定的 String 匹配。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = (Label1.Text.EndsWith(".exe")).ToString();
   Label3.Text = "asdfasdfasdfexe";
   Label4.Text = (Label3.Text.EndsWith(".exe")).ToString();
8、String.Length 属性 获取此实例中的字符数。  
9、String.IndexOf 属性 在此实例中的第一个匹配项的索引或一个或多个字符的索引。
10、String.IndexOfAny 属性 报告指定 Unicode 字符数组中的任意字符在此实例中第一个匹配项的索引。
11、String.LastIndexOfAny  属性 报告在 Unicode 数组中指定的一个或多个字符在此实例中的最后一个匹配项的索引位置。
12、String.LastIndexOf 指定的 Unicode 字符或 String 在此实例中的最后一个匹配项的索引位置。
   Label1.Text = "asd.fasdf.exe";
   Label2.Text = (Label1.Text.LastIndexOf(".")).ToString(); 

13、String.Substring(int开始位置,int长度) 方法 从此实例检索子字符串。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = Label1.Text.Substring(Label1.Text.LastIndexOf("."),(Label1.Text.Length-Label1.Text.LastIndexOf("."))).ToString();
  
14、String.Replace 将此实例中的指定 Unicode 字符或 String 的所有匹配项替换为其他指定的 Unicode 字符String。
   Label1.Text = "asdfasdf.exe";
   Label2.Text = Label1.Text.Replace("asd","XXX");
15、String.Remove 方法 从此实例中的指定位置开始删除指定数目的字符。
16、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)+"...";



分享
原创粉丝点击