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#
string convert(string text)
{
string pattern = @"$1\\";
string repPattern =@"";
string returnText = Regex.Replace(text, repPattern, pattern);
return returnText;
}
What is assigneed to 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
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.