星期一, 12月 17, 2018

筆記-C# 擷取某區間字串

string aa = abc(a b c)aaa
 int firstIndex = 0;
 int endIndex = 0;
 firstIndex = aa.IndexOf("(");//定位(位置
 endIndex = aa.IndexOf(")");//定位)位置
 string tmpStr = "";
 string ReportTmpStr = "";
 ReportTmpStr = aa;
 if (firstIndex >= 0 && endIndex >= 0)
 {
       tmpStr = ReportTmpStr.Substring(firstIndex, endIndex + 1);//擷取出(a b c)

       string ReportTmpStr2 = tmpStr.Replace(" ", "");//取代空格
       ReportTmpStr = ReportTmpStr.Replace(tmpStr, ReportTmpStr2);
 }

沒有留言: