c#Substring截取字符方法

 
string dest = "aaa,bbb,cccc,abcd 100,dddd,eeee,200,ffff";
  int pos100 = dest.LastIndexOf(",", dest.IndexOf("100"));
  int pos200 = dest.LastIndexOf(",", dest.IndexOf("200"));
  if (((pos100 == -1) || (pos200 == -1))
  || (pos200 <= pos100))
  {
  throw new Exception("string doesn't include 100 or 200, or 200 is before 100");
  }

  string res = dest.Substring(0, pos100) + dest.Substring(pos200, dest.Length - pos200);

最后res是aaa,bbb,cccc,200,ffff 

 

c#的 Substring(x,y);注意y表示的是截取的长度。x是开始位置。
我觉得c#的Substring()方法没有java的Substring()方法好用。

你可能感兴趣的:(java,exception,String,C#,include)