How to remove lowercase on a textbox?

后端 未结 11 1831
难免孤独
难免孤独 2020-12-31 02:47

I\'m trying to remove the lower case letters on a TextBox..

For example, short alpha code representing the insurance (e.g., \'BCBS\' for \'Blue Cross B

11条回答
  •  一向
    一向 (楼主)
    2020-12-31 03:36

    Rather than matching on all capitals, I think the specification would require matching the first character from all the words. This would allow for inconsitent input but still be reliable in the long run. For this reason, I suggest using the following code. It uses an aggregate on each Match from the Regex object and appends the value to a string object called output.

    string input = "Blue Cross BLUE shield 12356";
    Regex regex = new Regex("\\b\\w");
    string output = regex.Matches(input).Cast().Aggregate("", (current, match) => current + match.Value);
    Console.WriteLine(output.ToUpper()); // outputs BCBS1
    

提交回复
热议问题