2016-11-09 42 views
-3

我想從我獲得的是在調試字符串中刪除,從字符串在asp.net刪除最後一個字符不工作

27/1, 106/2,

注意,後有空間了。

所以。我試着用下面的代碼

if (txt712.Text != "") 
     { 
      string strText = txt712.Text; 

      strText = strText.Remove(strText.Length - 2, 1); 
      xw.WriteElementString("SURVEY_AREA_7_12", strText); 
     } 

但同時節省它給我的錯誤作爲

無效的號碼

+0

要刪除所有「,」還是隻刪除最後一個。 – lukai

回答

0

使用此代碼..

var str = "127/10,"; 
var TrimedStr= str.substring(0, str.length-1); 
0

使用Trim()它將從字符串中刪除空白區域併爲r刪除Regex.Replace eplacing ,

  if (txt712.Text != "") 
      { 
       string strText = txt712.Text; 
       strText = Regex.Replace(strText.Trim(),",", ""); 
       xw.WriteElementString(strText); 
      } 
0

strText中= strText.Trim()代替( ' ''');

0

如果你想如果你想刪除所有「」最後的空間

str = str.Trim().Replace(",", ""); 

在你的代碼刪除,只有最後一個

str = str.Substring(0, str.Length - 1); 

我不知道什麼xw.WriteElementString呢。 所以我認爲還有一些其他的邏輯錯誤,xw.WriteElementString不接受字符串值。

相關問題