2014-05-20 171 views
-1

我有字符串例如。 ,,,, ABC從字符串Asp.net刪除逗號

TextBox box2 = (TextBox)GV_Assoceries.Rows[rowIndex].Cells[2].FindControl("TextBox2"); 
    box2.text; 

基本上我創建的onclick事件的GridView的新行和settting一個GridView行的前一個數據時,每個新行會加入那麼它將設置上一行的前一個數據,但不知道爲什麼我在每個字符串中都得到逗號。

box2.text有一個值「,,,,, abc」,我想從字符串中只刪除逗號,我不想要任何字符串循環做到這一點。

沒有任何函數或方法從字符串

+0

您需要提供更多的信息來解決實際問題。 –

回答

2

試試看可能比較慢,但是它一定要幫助

string abc = "....abc"; 
string trimmedResult = new String(abc.Where(Char.IsLetterOrDigit).ToArray()); 
+0

感謝它的工作 –

1

Click me你應該參考這個刪除特定的字符。

MSDN例

using System; 

public class Example 
{ 
    public static void Main() 
    { 
     String header = "* A Short String. *"; 
     Console.WriteLine(header); 
     Console.WriteLine(header.Trim(new Char[] { ' ', '*', '.' })); 
    } 
} 
// The example displays the following output: 
//  * A Short String. * 
//  A Short String 

凡新字符[]是要移除形成串指定的頭一個字符數組。

5

box2.text.Replace(",", String.Empty) 
+0

我懷疑這是否解決了實際問題。它只會影響症狀而不是原因。 –

+0

我也是,我不知道爲什麼這是upvoted。 –

+0

@StijnBernards:你的回答並不是指OP的實際問題。爲什麼附加逗號?這就像修理牆壁以解決汽車剎車問題。 –

相關問題