文章目录  Length:获取字符串中字符的个数(不包括末尾的空字符) ToLower() 和 ToUpper():将字符串转换为小写或大写形式 Substring(int startIndex, int length):从指定索引开始截取指定长度的子字符串 Remove(int startIndex, int length):从指定索引开始移除指定长度的字符 Replace(string oldValue, string newValue):替换字符串中的指定字符或子字符串 Split(char[] separator, StringSplitOptions options) :根据指定的分隔符拆分字符串 IndexOf(char value) 和 IndexOf(string value):查找指定字符或子字符串在字符串中第一次出现的位置 LastIndexOf(char value) 和 LastIndexOf(string value):查找指定字符或子字符串在字符串中最后一次出现的位置 Trim()、TrimStart() 和 TrimEnd():移除字符串开头、结尾或两端的空白字符(包括空格、制表符和换行符) Contains(string value):判断字符串是否包含指定的子字符串 StartsWith(string value) 和 EndsWith(string value):判断字符串是否以指定的子字符串开始或结束 PadLeft(int totalWidth) 和 PadRight(int totalWidth):在字符串的左侧或右侧填充空格,直到达到指定的总宽度 Join(string separator, params string[] values):将多个字符串连接成一个字符串,并使用指定的分隔符分隔它们 Format(string format, params object[] args):格式化字符串,将指定的参数插入到格式字符串中 IsNullOrEmpty(string value):判断字符串是否为空或null IsNullOrWhiteSpace(string value):判断字符串是否为空、null或仅包含空白字符 Concat(params string[] values):连接多个字符串并返回一个新的字符串 CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count):将字符串中的字符复制到指定的字符数组中 IndexOfAny(char[] anyOf) 和 LastIndexOfAny(char[] anyOf):查找字符数组中字符在字符串中第一次或最后一次出现的位置 PadLeft(int totalWidth, char paddingChar) 和 PadRight(int totalWidth, char paddingChar):在字符串的左侧或右侧填充指定的字符,直到达到指定的总宽度 Remove(int startIndex):从指定索引开始移除字符串的剩余部分 Insert(int startIndex, string value):在指定索引处插入一个字符串 字符串插值(String Interpolation)(C# 6.0及更高版本):使用$符号和大括号{}来嵌入变量或表达式,从而创建格式化的字符串   
 
string =  "Hello" ; 
Console. WriteLine ( str. Length) ;  
string =  "Hello" ;   
Console. WriteLine ( str. ToLower ( ) ) ;  
Console. WriteLine ( str. ToUpper ( ) ) ;  
string =  "Hello World" ;  
Console. WriteLine ( str. Substring ( 6 ,  5 ) ) ;  
string =  "Hello World" ;  
Console. WriteLine ( str. Remove ( 6 ,  5 ) ) ;  
string =  "Hello World" ;   
Console. WriteLine ( str. Replace ( 'o' ,  '0' ) ) ;  
Console. WriteLine ( str. Replace ( "World" ,  "C#" ) ) ;  
string =  "Hello,World,C#" ;   
string [ ] =  str. Split ( new  char [ ] {  ','  } ,  StringSplitOptions. RemoveEmptyEntries) ;   
foreach  ( string in  parts)   
{   Console. WriteLine ( part) ;  
} 
string =  "Hello World" ;   
Console. WriteLine ( str. IndexOf ( 'W' ) ) ;  
Console. WriteLine ( str. IndexOf ( "World" ) ) ;  
string =  "abc abc abc" ;   
Console. WriteLine ( str. LastIndexOf ( 'a' ) ) ;  
Console. WriteLine ( str. LastIndexOf ( "abc" ) ) ;  
string =  "   Hello World   " ;   
Console. WriteLine ( str. Trim ( ) ) ;  
Console. WriteLine ( str. TrimStart ( ) ) ;  
Console. WriteLine ( str. TrimEnd ( ) ) ;  
string =  "Hello World" ;  
Console. WriteLine ( str. Contains ( "World" ) ) ;  
string =  "Hello World" ;   
Console. WriteLine ( str. StartsWith ( "Hello" ) ) ;  
Console. WriteLine ( str. EndsWith ( "World" ) ) ;  
string =  "123" ;   
Console. WriteLine ( str. PadLeft ( 5 ) ) ;  
Console. WriteLine ( str. PadRight ( 5 ,  '*' ) ) ;  
string [ ] =  {  "Hello" ,  "World" ,  "C#"  } ;   
string =  string . Join ( ", " ,  words) ;   
Console. WriteLine ( sentence) ;  
string =  "John" ;   
int =  30 ;   
string =  string . Format ( "Name: {0}, Age: {1}" ,  name,  age) ;   
Console. WriteLine ( formattedString) ;  
string =  null ;  
Console. WriteLine ( string . IsNullOrEmpty ( str) ) ;  
string =  " " ;  
Console. WriteLine ( string . IsNullOrWhiteSpace ( str) ) ;  
string =  string . Concat ( "Hello" ,  " " ,  "World" ) ;  Console. WriteLine ( result) ;  
char [ ] =  new  char [ 5 ] ;   
string =  "Hello" ;   
str. CopyTo ( 0 ,  charArray,  0 ,  5 ) ;   
Console. WriteLine ( new  string ( charArray) ) ;  
string =  "Hello World" ;   
char [ ] =  {  'o' ,  'W'  } ;   
Console. WriteLine ( str. IndexOfAny ( chars) ) ;  
Console. WriteLine ( str. LastIndexOfAny ( chars) ) ;  
string =  "123" ;   
Console. WriteLine ( str. PadLeft ( 5 ,  '*' ) ) ;  
Console. WriteLine ( str. PadRight ( 5 ,  '*' ) ) ;  
string =  "Hello World" ;  
Console. WriteLine ( str. Remove ( 6 ) ) ;  
string =  "Hello" ;  
Console. WriteLine ( str. Insert ( 5 ,  " World" ) ) ;  
int =  30 ;   
string =  "Alice" ;   
string =  $"My name is  { name }  and I am  { age }  years old." ;   
Console. WriteLine ( message) ;