如何删除数据表中的特殊字符? [英] How to remove special characters in data table?
本文介绍了如何删除数据表中的特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我有一个Datatable.it只有两列。如果第一行数据表有任何特殊字符它将被删除。我可以这样做。
Here I have one Datatable.it has two columns only.if first row of datatable has any special characters it will deleted.how can i do this.
推荐答案
我不确定你的'特殊字符'是什么意思,但是如果你想控制控制字符你可以做这样的事情。
I'm not sure what you mean by 'special characters' but if you want to trap control characters you can do something like this.
string MyString = "FirstLine\r\nSecondLine\t tabbed";
if (MyString.Any(c => char.IsControl(c)))
{
Console.WriteLine("Found Control character");
}
foreach(dt.Rows中的DataRow行)
{
for (int i = 0; i< dt.Columns.Count; i ++)
{
if(dt.Columns [i] .DataType == typeof(string) )
row [i] = ReplaceHexadecimalSymbols((string)row [i]);
}
}
我的不好,我看了它
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
if(dt.Columns[i].DataType == typeof(string))
row[i] = ReplaceHexadecimalSymbols((string)row[i]);
}
}
my bad, i over looked it
static string ReplaceHexadecimalSymbols(string txt)
{
string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";
return Regex.Replace(txt, r,"",RegexOptions.Compiled);
}
这篇关于如何删除数据表中的特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文