2011-05-31 35 views
1
之间

我有这样的字符串:词赔率

“article.DOS = 998和article.des = 'toto.tata' 或article.des = ”ot.o“”

NB:所述整个字符串是单个字符串。

我希望把每word.word以大写字母,但不言开始,以“或”

我现在的正则表达式是结尾:Regex rgx = new Regex(@"\S+\.\S+");

最后,我的字符串应该是:

“ARTICLE.DOS = 998和ARTICLE.DES = 'toto.tata' 或ARTICLE.DES = ”ot.o“”

,使其在上部的情况下,我使用:

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)); 
} 

由于

+0

'[\ w \ S _-]'可以缩写为'\ S' – Toto 2011-05-31 08:37:14

+0

@ M42:没错,Thx! – Xavinou 2011-05-31 08:39:55

回答

2
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)); 
    } 
+0

谢谢,但我看到我misspoke:我的字符串是一个单一的字符串:“article.DOS = 998和article.des ='toto.tata'或article.des =”ot.o“”。 – Xavinou 2011-05-31 08:29:50

+0

谢谢,这工作正常:) – Xavinou 2011-05-31 08:52:44

0

如何

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和ARTICLE.DES = 'toto.tata' 或ARTICLE.DES =” ot.o “

+0

不,没有必要在word.word – Xavinou 2011-05-31 08:50:39

+0

后面有空格。现在它处理。 – 2011-05-31 09:13:19

+0

谢谢,但字符串也可以是:“article.DOS,article.REF,...” – Xavinou 2011-05-31 10:00:23