473,662 Members | 2,575 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 5757
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***********@g mx.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(obje ct 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.Re gularExpression s.Regex.IsMatch (s,
sPattern, System.Text.Reg ularExpressions .RegexOptions.I gnoreCase))
{
MessageBox.Show ( sPattern.ToUppe r());
}
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(strin ga|stringb|stri ngc)\b", RegexOptions.Co mpiled
| RegexOptions.Ig noreCase);

public string UpperSpecialWor ds(string input)
{
return rx.Replace(inpu t, new MatchEvaluator( UpperSpecialWor dsImpl));
}

private string UpperSpecialWor dsImpl(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
1945
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: ------------------------------------------------- function findNumeric(str_obj){ regEx = /\d/; if (str_obj.match(regEx))
7
5722
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 is to improve, but not to prove.
2
3421
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 was splitted. I am fascinated to the powerfull use of this RegEx class, so I wonder if it could go a step further. As a question, can regex be used to valid a set of different functions ? Example : Suppose I have to verify the correctness of an...
5
1591
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 for: "great" AND "car" and what about upper case
4
1914
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: cond(c,a,b)
3
2362
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 '<' character. My strSearch is ok, but my strReplace doesn't seem to do anything. Anyone know how to get my desired result? Thanks, Paul
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
1908
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 Camel Case Property Name" (fully expanding upper-case blocks as the simplest answer to the ambiguity) Console.WriteLine(Regex.Replace( @"testInputOfWhatIWantUPPERS",
4
1588
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
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.