开发者

Words not between odds

开发者 https://www.devze.com 2023-03-09 04:12 出处:网络
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 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"

0

精彩评论

暂无评论...
验证码 换一张
取 消