Replacing strings...

    Date: 07/15/07 (C Sharp)    Keywords: no keywords

    Hi, just joined!

    I'm working on a program which has to generate reports based on some data. I want to be able to specify a template for the report, using placeholders like %a or %b for various bits of data.

    Seems like this should be extremely simple, using the String.Replace method, however I'm trying that and nothing at all is getting replaced. Here's an example:

    TextWriter tw = new StreamWriter(filename);
    
    String headerText = header.Text;
    headerText = headerText.Replace("&&", "&");
    headerText = headerText.Replace("&t", trainerName.Text);
    headerText = headerText.Replace("&a", tradable.ToString());
    headerText = headerText.Replace("&w", wanted.ToString());
    headerText = headerText.Replace("&d", diamondFriendCode.Text);
    headerText = headerText.Replace("&p", pearlFriendCode.Text);
    headerText = headerText.Replace("&b", battleRevFriendCode.Text);
    headerText = headerText.Replace("&", "&");
    
    if (displayHeader.Checked)
         tw.WriteLine(headerText);


    Here's the contents of the form element "header:"

    %t's trade list
    Friend codes:
    Diamond: %d
    Pearl: %p
    Battle Revolution: %b


    And here's the output from the program for that portion, which of course is identical to the input:

    %t's trade list
    Friend codes:
    Diamond: %d
    Pearl: %p
    Battle Revolution: %b


    Any ideas?

    Source: http://community.livejournal.com/csharp/85552.html

« Web Browser code in C# || Dynamic Detection? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home