using System.Collections.Generic;
using System.Linq;
using System.Text;
{
class Program
{
static void Main(string[] args)
{
string str = "123456789078ABab你好吗";
Console.WriteLine(str.IndexOf('0')); //数字0的索引是9
Console.WriteLine(str.IndexOf("4"));//数字4的索引是3
Console.WriteLine(str.IndexOf('0', 4));//从索引为4的数字开始一次查找0
Console.WriteLine(str.CompareTo("你好吗"));//比较两个字符串是否相等,相等返回0
Console.WriteLine(str.IndexOfAny(b).ToString());//报告指定 b数组中的任意字符在str此中第一个匹配项的索引此时表示'5'在str中的索引为4
if (str.Contains("你好不"))
{
Console.WriteLine(str);
}
else
Console.WriteLine("不包含");
char [] a={'1','2','3','4'};
foreach (char b in a)
{
Console.WriteLine(b.ToString ());
}
//确定 String 的实例的末尾是否与指定的字符串匹配
if (str.EndsWith("吗"))
{
Console.WriteLine("包含");
}
else
Console.WriteLine("不包含");
Console .WriteLine ( str.Insert(3, "圭贤"));//在str索引为3的地方插入字符串圭贤
string.IsInterned(str);//检索对指定 String 的引用
string.IsNullOrEmpty(str);//指示指定的 String 对象是 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing) 还是 Empty 字符串。
Console .WriteLine ( string.IsNullOrEmpty(str));
string.Join();
Console .WriteLine ( str .LastIndexOf ( '7'));//报告在str中与7匹配的最后一个字符串的索引
Console.WriteLine(str.LastIndexOf("7"));
str.LastIndexOfAny();//报告在 Unicode 数组中指定的一个或多个字符在此实例中的最后一个匹配项的索引位置
char[] c = { '5', '好', '8' };
Console.WriteLine(str.LastIndexOfAny(c));//数组c中的元素在str中的最后一个匹配项的索引位置
Console.WriteLine(str.LastIndexOfAny(c,3));
Console.WriteLine(str.PadLeft(30));
Console .WriteLine ( str .PadLeft (30,'不'));
//左对齐此字符串中的字符,在右边用空格或指定的 Unicode 字符填充以达到指定的总长度。
Console.WriteLine(str.PadRight(30));
Console.WriteLine(str .PadRight (30,'不'));
Console.WriteLine(str.Remove(3, 5));
Console.WriteLine(str .Replace('1','b'));
Console.WriteLine(str.Replace("1", "b"));
str.Split();
Console.WriteLine ( str.StartsWith("123"));
Console.WriteLine(str.Substring(3, 4));//从此实例检索子字符串
str.ToCharArray(2, 6);//将此实例中的字符复制到 Unicode 字符数组。
{
Console.WriteLine(c.ToString());
}
Console.WriteLine(str.ToLower());//返回此 String 转换为小写形式的副本
Console.WriteLine(str.ToUpper());//返回此 String 转换为大写形式的副本
str.TrimStart();//从当前 String 对象移除数组中指定的一组字符的所有前导匹配项
str.Trim();//从当前 String 对象移除一组指定字符的所有前导匹配项和尾部匹配项。
}
}
}