Words not between odds
I have strings like :
"article.DOS = 998 and article.des = 'toto.tata' or article.des = "ot.o""
NB : the whole string is a single string.
I'd like to put every word.word in upper case, but not words beginning and ending with ' or "
My current regex is : Regex rgx = new Regex(@"\S+\.\S+");
In the end, my string should be :
"ARTICLE.D开发者_如何学编程OS = 998 and ARTICLE.DES = 'toto.tata' or ARTICLE.DES = "ot.o""
To make it in upper case, I use :
private static string MeToUpper(Match m)
{
return m.Value.ToUpper();
}
internal string ToUpper(string codeSql)
{
Regex rgx = new Regex(@"\S+\.\S+");
return rgx.Replace(codeSql, new MatchEvaluator(MeToUpper));
}
Thanks
private static string MeToUpper(Match m)
{
return ((m.Value[0] != '\'') && (m.Value[0] != '\"'))
? m.Value.ToUpper()
: m.Value;
}
internal static string ToUpper(string codeSql)
{
Regex rgx = new Regex("(\'|\")?\\S+\\.\\S+");
return rgx.Replace(codeSql, new MatchEvaluator(MeToUpper));
}
How about
var s = @"article.DOS = 998 and article.des = 'toto.tata' or article.des = ""ot.o""";
var upper = new Regex(@"[a-z]+\.[a-z]+\s+[^""']", RegexOptions.IgnoreCase)
.Replace(s, m => m.Value.ToUpper());
=> "ARTICLE.DOS = 998 and ARTICLE.DES = 'toto.tata' or ARTICLE.DES = "ot.o"
精彩评论