I am trying to write a Regex pattern to modify the caption of my datagridview.
I need to remove following characters from each string:
space
[
]
*
#
?
/
\
@
(
)
.
""
''
I am super confused and I need your help in defining the patter of the Regex in C#. This is my sample code:
DataTable d_new = d;
for (int i = 0; i < d.Columns.Count; i++)
{
string t = d.Columns[i].Caption;
string regex = "\\s+"; // this needs to Be expanded
string t_new = Regex.Replace(t, regex, "_");
d.Columns[i].Caption = t_new;
}
L.B :
var invalidChars = new HashSet<char>(@\"[]*#?/\\@()\");\nvar output = new string( input.Where(c => !invalidChars.Contains(c)).ToArray() );\n",
2012-08-24T18:19:24
sQVe :
This would match what you want, just replace with an empty string or what you want.\n\n[ \\[\\]*#?/\\\\@().\"']\n\n\nBut in this case an regex is a bit overkill, you could just use Remove.",
2012-08-24T18:16:39