c# - Replace one word with different values -


i have string "{day} - victory day. {day} - birthday";

how replace {day} different numbers? try:

string text = "{day} - victory day. {day} - birthday"; if (text.contains("{day}"))     text = text.replace("{day}", xnet.rand.next(1, 30).tostring()); 

but day same in 2 replacements.

use regex.replace matchevaluator delegate:

string text = "{day} - victory day. {day} - birthday"; text = regex.replace(text, @"\{day\}", m => xnet.rand.next(1, 30).tostring()); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -