Convert all first letter to upper case, rest lower for each word

前端 未结 11 2073
一向
一向 2020-12-04 10:15

I have a string of text (about 5-6 words mostly) that I need to convert.

Currently the text looks like:

THIS IS MY TEXT RIGHT NOW

I

11条回答
  •  北海茫月
    2020-12-04 10:47

    Untested but something like this should work:

    var phrase = "THIS IS MY TEXT RIGHT NOW";
    var rx = new System.Text.RegularExpressions.Regex(@"(?<=\w)\w");
    var newString = rx.Replace(phrase,new MatchEvaluator(m=>m.Value.ToLowerInvariant()));
    

    Essentially it says "preform a regex match on all occurrences of an alphanumeric character that follows another alphanumeric character and then replace it with a lowercase version of itself"

提交回复
热议问题