Replacing strings... (original) (raw)
Yeah, just go ahead and ignore this. I flew too close to the sun stayed up too late and made an incredibly stupid mistake.
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?