java 字符串的截取

string str="123abc456";
int i=3;
  1. 取字符串的前i个字符
   str=str.Substring(0,i); 
   // or
   str=str.Remove(i,str.Length-i); 
  1. 去掉字符串的前i个字符:
str=str.Remove(0,i);  
   // or
str=str.Substring(i); 
  1. 从右边开始取i个字符:
str=str.Substring(str.Length-i); 
  // or 
str=str.Remove(0,str.Length-i);

4 从右边开始去掉i个字符:

str=str.Substring(0,str.Length-i); 
   // or 
str=str.Remove(str.Length-i,i);
  1. 如果字符串中有"abc"则替换成"ABC"
   str=str.Replace("abc","ABC");
最后修改:2020 年 08 月 28 日
哇卡哇卡