从String Asp.net中删除逗号

时间:2014-05-20 09:12:44

标签: c# asp.net

我有字符串,例如。 ,,,, ABC

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

基本上我正在通过onclick事件创建一个新的gridview行,并在每个新行添加时设置gridview行的先前数据,然后它将设置上一行的先前数据,但不知道为什么我是在每个字符串中加入逗号..

box2.text有一个值“,,,,, abc”,我想只从字符串中删除逗号,我不希望任何循环来执行此操作。

是否有任何函数或方法从字符串中删除特定字符

3 个答案:

答案 0 :(得分:5)

尝试

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

答案 1 :(得分:2)

它可能会更慢,但它肯定会有所帮助

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

答案 2 :(得分: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

新Char []是要从名为header的字符串中删除的字符数组。