473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

RegEx upper case swap

How can I use RegEx to search for a number of strings and replace them with
upper case versions of themselves?

Thanks
Aug 9 '07 #1
3 5730
Bob wrote:
How can I use RegEx to search for a number of strings and replace them with
upper case versions of themselves?
Using Regex.Replace:
http://www.knowdotnet.com/articles/r...ntstrings.html

--
Daniel Strigl [da***********@gmx.takethisout.at, remove 'takethisout.']
Web: http://www.hh-system.com/danielstrigl
Blog: http://geekswithblogs.net/dastblog
Aug 9 '07 #2
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);

if (System.Text.RegularExpressions.Regex.IsMatch(s,
sPattern, System.Text.RegularExpressions.RegexOptions.Ignore Case))
{
MessageBox.Show ( sPattern.ToUpper());
}
else
{
MessageBox.Show("");
}
}

}
ref:http://msdn2.microsoft.com/en-us/lib...95(VS.80).aspx
--
Hope this answers your question.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Bob" wrote:
How can I use RegEx to search for a number of strings and replace them with
upper case versions of themselves?

Thanks
Aug 9 '07 #3
Hello Bob,
How can I use RegEx to search for a number of strings and replace them
with upper case versions of themselves?

Thanks
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
Aug 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
2
by: Tim Conner | last post by:
Hi, Thanks to Peter, Chris and Steven who answered my previous answer about regex to split a string. Actually, it was as easy as create a regex with the pattern "/*-+()," and most of my string...
5
by: Kijak | last post by:
Hi, Im just starting working with REGEX and got a few problems. Could you tell me how to test if two strings can be found in another. ei: String to test: "This is a great car you got" Look...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
3
by: a | last post by:
In the example below, I'm trying to simply find all the date values in an XML document (the XML is a string in this example) and then add an upper case Z between the last digit and the closing '<'...
0
by: =?Utf-8?B?Qm9i?= | last post by:
How can I use RegEx to search for a number of strings and replace them with upper case versions of themselves? Thanks
2
by: Marc Gravell | last post by:
Blonde moment... Before I try and do it a harder way, can anybody remind me how to get the desired from the following? I simply want to split "aTypicalCamelCasePropertyName" into a "a Typical...
4
by: timor.super | last post by:
I have a string, for example : string str = "abCdEfGhiJKl"; to find "def", ignoring the case, i'm doing if (str.toLower().Contains("def")) { // do something }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.