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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -