Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to add placement variable into a resource string

Tags:

c#

resources

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

like image 578
scope_creep Avatar asked Jun 17 '09 19:06

scope_creep


1 Answers

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);
like image 190
Sailing Judo Avatar answered Oct 22 '22 00:10

Sailing Judo