Skip to content

Instantly share code, notes, and snippets.

@chrisswong
Created August 22, 2018 14:20
Show Gist options
  • Save chrisswong/19124d1e07fdf4953981979bf785e575 to your computer and use it in GitHub Desktop.
Save chrisswong/19124d1e07fdf4953981979bf785e575 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string s = "abcd %(dbac) acd";
var dict = new Dictionary<string, object>();
dict.Add("dbac", 124);
Console.WriteLine( RepalceTokenString(s, dict));
Console.ReadLine();
}
static string RepalceTokenString(string s, Dictionary<string, object> dict)
{
foreach (var item in dict)
{
string token = "%(" + item.Key + ")";
s = s.Replace(token, item.Value.ToString());
}
return s;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment