.net - Regular Expression in c# to find letter then \ with capital letter for letter and Shift press form of other charecter? -
i want convert string m\anoj ku\mar m\a\noj
manoj kumar manoj
how can using c#
string convert(string text) { string pattern = @"$1\\"; string reppattern =@""; string returntext = regex.replace(text, reppattern, pattern); return returntext; }
what assigneed reppattern ? 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 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);
Comments
Post a Comment