Showing Tag: "replacing" (Show all posts)

Replacing C# String with use of dictionary

Posted by jineesh uvantavida on Thursday, August 9, 2018,
For this the string data should be tokenized (i.e. "Dear $name$, as of $date$ your balance is $amount$"). For this purpose, we can use Regex.

static readonly Regex re = new Regex(@"\$(\w+)\$", RegexOptions.Compiled);
static void Main() {
    string input = @"Dear $name$, as of $date$ your balance is $amount$";

    var args = new Dictionary<string, string>(
        StringComparer.OrdinalIgnoreCase) {
            {"name", "Mr Smith"},
            {"date", "05 Aug 2009"},
            {"amount", ...

Continue reading ...
 
 

Translate This Page

 


Make a free website with Yola