Having trouble with Regular Expression and Ampersand
Posted
by ajax81
on Stack Overflow
See other posts from Stack Overflow
or by ajax81
Published on 2010-04-23T17:37:38Z
Indexed on
2010/04/23
17:43 UTC
Read the original article
Hit count: 469
Hi All,
I'm having a bit of trouble with regex's (C#, ASP.NET), and I'm pretty sure I'm doing something fundamentally wrong. My task is to bind a dynamically created gridview to a datasource, and then iterate through a column in the grid, looking for the string "A&I". An example of what the data in the cell (in template column) looks like is:
Name: John Doe
Phone: 555-123-1234
Email: [email protected]
Dept: DHS-A&I-MRB
Here's the code I'm using to find the string value:
foreach(GridViewRow gvrow in gv.Rows)
{
Match m = Regex.Match(gvrow.Cells[6].Text,"A&I");
if(m.Success)
{
gvrow.ForeColor = System.Drawing.Color.Red;
}
}
I'm not having any luck with any of these variations: "A&I" "[A][&][I]"
But when I strictly user "&", the row does turn red. Any suggestions?
Thanks, Dan
© Stack Overflow or respective owner