c# - String replace with pattern matching -
i have following variable string pulled database , changes each time:
for example first time string is:
you can use [xyz] framework develop [123], web, , [abc] apps
second time string is:
you can use [aaa] framework develop [bbb], web, , [ccc] apps
i replace
[xyz]
or [aaa].net
,[123]
or [bbb]desktop
, and[abc]
or [ccc]mobile
.
the text in braces change since variable string want replace the text in first brace .net
, text in second brace desktop
, text in third brace mobile
.
the transformed string should -
you can use .net framework develop desktop, web, , mobile apps:
what easiest way using string replace in c#?
you can want regular expressions:
// error checking needed..... string input = "you can use [xyz] framework develop [123], web, , [abc] apps"; regex re = new regex(@"(\[[^\]]+\])"); matchcollection matches = re.matches(input); input = input.replace(matches[0].value, ".net").replace(matches[1].value, "desktop").replace(matches[2].value, "mobile");
Comments
Post a Comment