473,406 Members | 2,356 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,406 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 5731
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.