Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
[no name] 30-Dec-14 2:13am    
Use a loop and check for each cell data with the special characters that you want to check and perform your operation that you wanted to do.

I'm not sure what you mean by 'special characters' but if you want to trap control characters you can do something like this.


C#
string MyString = "FirstLine\r\nSecondLine\t tabbed";
             if (MyString.Any(c => char.IsControl(c)))
            {
                Console.WriteLine("Found Control character");
            }
 
Share this answer
 
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

C#
static string ReplaceHexadecimalSymbols(string txt)
{
string r = "[\x00-\x08\x0B\x0C\x0E-\x1F\x26]";
return Regex.Replace(txt, r,"",RegexOptions.Compiled);
}
 
Share this answer
 
v2
Comments
Maciej Los 2-Sep-15 2:22am    
ReplaceHexadecimalSymbols? There's no inbuilt method to replace hexadecimal symbols. Did you forget to post this method?
dev_assault 6-Oct-15 10:20am    
Thanks for correcting Maciej and the credit for this answer goes to this
http://stackoverflow.com/questions/22832974/remove-special-character-from-datatable
although i faced it long back, so i knew the solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900