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
Post a Comment