tags:

views:

685

answers:

3

Hi,

This should be easy, but can't find anything to explain it.

Say I am writing something out on console.writeln like:

console.writeln("Jim is a {0} ", xmlscript);

Say I wanted to convert string `"Jim is.." to a resource string in a global resource.resx. It would be:

jimstring jim is a {0}

and I would refer to it in code as

console.writeln(Resources.jimstring)

How to I put the placement variable (xmlscript) (is this what they are called?) into the resource string in console.writeln?

Thanks,

Bob

+4  A: 
Console.WriteLine(Resources.jimstring, xmlscript);

Console.WriteLine takes additional formatting arguments that will replace the {0} in your Resources.jimstring string.

More info here: http://msdn.microsoft.com/en-us/library/828t9b9h.aspx

John JJ Curtis
What would happen if you put it into a TraceEvent likeTraceEvent(TraceEventType.Error, 0, formattedDate + ": " + Resources.jimstring)for some reason I can't get it to work. Bob.
scope_creep
Can you add this code to your original question? What is the type of formattedDate?
John JJ Curtis
A: 

Is XMLScript a constant of some kind, to be put it into a resource file?

shahkalpesh
could be a string, or int generally.
scope_creep
A: 

As Jeff Johnson mentioned in his answer, it basically the exact same thing as the original Console.WriteLine(). The resource string is just a string. So you reference the resource file and do the format.

If you need it for something other than the Console you can use the String.Format():

  var newString = String.Format(resources.jimstring, xmlscript);
Sailing Judo