Instead of using regex, use:
name.Contains("Amount")
this should return a boolean as to whether Amount is in the string.
You don't need regex for this situation (and sometimes it's good to go without when unnecessary)
as others suggested,
name.IndexOf("amount", StringComparison.OrdinalIgnoreCase) >= 0;
could also be used to include "AMOUNT", "amount", "AmOunT", etc.
Or:
name.IndexOf("amount", StringComparison.OrdinalIgnoreCase)!= -1
We're just checking that IndexOf doesn't send back -1 for 'not found'.
The reason you might not want to use:
name.ToLower().Contains("amount")
is because it will have problems with international characters (accents, etc).
If you were passing in a variable that could have any text, that could pose a problem.
For a case with a constant string, it might be fine, however (though not extremely recommended)
Edit:
If I understand C# correctly (not my expertise, though i've used it), this should work:
foreach (string name in Request.Form.AllKeys)
{
if (name.IndexOf("amount", StringComparison.OrdinalIgnoreCase) >= 0)
{
Response.Write(Request.Form[name]);
}
else
{
Response.Write("Not working\n");
}
}
I see an extra brace in your code. Is that supposed to be there?