473,508 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5738
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
1935
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
5712
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
3411
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
1588
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
1905
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
2351
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
246
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
1901
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
1583
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
7227
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
7127
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...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.