Hi,
You can try something like this:
private void Form1_Load(object sender, EventArgs e)
{
string[] sentences =
{
"cow over the moon",
"Betsy the Cow",
"cowering in the corner",
"no match here"
};
string sPattern = "cow";
foreach (string s in sentences)
{
System.Console.Write("{0,24}", s);
You cannot use a replacement pattern to indicate you want the found match
to become upper case. You can however use a MatchEvaluator to accomplish
this:
static Regex rx = new Regex("\b(stringa|stringb|stringc)\b", RegexOptions.Compiled
| RegexOptions.IgnoreCase);
public string UpperSpecialWords(string input)
{
return rx.Replace(input, new MatchEvaluator(UpperSpecialWordsImpl));
}
private string UpperSpecialWordsImpl(Match m)
{
return m.Value.ToUpper();
}
In the MatchEvaluator function you can manipulate the contents of the match
and return them as a string. These changes will be merged with the original
resultign in exactly what you need.
Jesse
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.