Last post May 03, 2012 12:41 AM by Paul Linton
May 02, 2012 09:36 PM|kalkal|LINK
i want to create a regular expression to find and replace uppercase character based on some condition.
Find the starting uppercase for a group of uppercase character in a string and replace it lowercase and "*" before the starting uppercase.
If there is any lowercase following the uppercase,replace the uppercase with lowercase and "*" before the starting uppercase.
input string : stackOVERFlow
expected output : stack*over*flow
i tried but could not get it working perfectly.
Any idea on how to create a regular expression ?
May 03, 2012 12:41 AM|Paul Linton|LINK
I don't do regular expressions but Linq is quite up to the challange
string x = "stackOVERFlow";
var y = x.ToCharArray()
((char.IsLower(x[pos]) && char.IsUpper(x[pos+1])) || //lower to upper
(char.IsUpper(x[pos+1]) && x.Length>pos+1 && char.IsLower(x[pos+2])) // upper to lower
.Aggregate (x.Substring(0,1), (sofar,c) => sofar+c );