简体   繁体   English

在c#中使用正则表达式来查找字母然后用大写字母和其他字符的移位表单?

[英]Regular Expression in c# to find letter then \ with capital letter for letter and Shift press form of other charecter?

I want to convert a string like m\\anoj ku\\mar m\\a\\noj to Manoj kUmar MAnoj how can i do this using c# 我想将像m\\anoj ku\\mar m\\a\\noj这样的字符串转换为Manoj kUmar MAnoj我怎么能用c#做到这一点

string convert(string text)
{
  string pattern = @"$1\\";
  string repPattern =@"";
  string returnText = Regex.Replace(text, repPattern, pattern);
  return returnText;
}

What is assigneed to repPattern ? 什么是repPattern? to get result 得到结果

Try following: 试试以下:

var input = @"m\anoj ku\mar m\a\noj";
var pattern = new Regex(@"([a-z])\\");
var replaced = pattern.Replace(input, m => m.Groups[1].ToString().ToUpper());
Console.WriteLine(replaced);

UPDATE UPDATE

Map digits to shift-pressed form: 将数字映射到按下移位的形式:

string text= @"m\an1oj ku\mar m\a\no9j";
char[] shiftPressForms = ")!@#$%^&*(".ToCharArray();
Regex pattern = new Regex(@"([a-z])\\");
Regex pattern_digit = new Regex(@"\d");
string replaced = pattern.Replace(text, m => m.Groups[1].ToString().ToUpper());
replaced = pattern_digit.Replace(replaced, m => shiftPressForms[int.Parse(m.Value)].ToString());
Console.WriteLine(replaced);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM