c# - REGEX character Set substitution -
i need regex pattern allow me substitute characters 1 set corresponding characters in set. example: set [abcdefg], should replaced set [1234567]... in string of "bag", want replacement "217".
regex regx = new regex("([abcdefg])([1234567])"); string result = regx.replace("bag", "$1$2");
my result same source. should replace pattern be?
something work much improve regex:
var fromcharacters = "abcdefghijklmnopqrstuvwxyz"; var tocharacters = "12345678901234567890123456"; var mystring = "bag"; var sb = new stringbuilder(mystring.length); (int = 0; < mystring.length; ++i) { sb.append(tocharacters[fromcharacters.indexof(mystring[i])]); } sb.tostring().dump();
you similar if want, example, 'j' turn '10', need array of strings instead of beingness able utilize string array of chars.
i'm not sure how regex, know shouldn't.
c# regex
No comments:
Post a Comment