Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have 2 strings..
C#
string firstword="Hello How Are You";
string correct=firstword.Replace("hello","h");

Now I want to replace firstword weather the first word is in upper case or lower it matches weather these both are same or not and then simply replaces...????
Does anyone have any ideas..????
Is there any way for adding ignorecase ...
Posted
Updated 30-Mar-10 23:36pm
v2

Kaiwa's Answer will have the effect of changing the rest of the string to lower case, this might not be the behaviour you want.

Regular Expressions[^] are a good way to go about what you want:

C#
string regularExpressionPattern = "zzz"
Regex regex = new Regex(regularExpressionPattern, RegexOptions.IgnoreCase);
string foo = "zZz this is sample text";
string bar = regex.Replace(foo, "Goodbye");



Note that my code just replaces "zzz", ignoring the case. If you want you replace the first word (rather than just "hello") you can create a regular expression to do this. Obviously, in either case, you'll need to work out the pattern for yourself :-).
 
Share this answer
 
v2
thanx for the answer
but if i dont know weather the string is in upper case or lower case bcz if the string is being generated from database den do i have any way to set ignorecase?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900