C # How to add placement variable to resource string

It should be easy, but cannot find anything to explain it.

Say I'm writing something on a .writeln console like:

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

Let's say I wanted to convert the string `` Jim is .. '' to a resource string in a global .resx resource. This will:

jimstring jim is a {0}

and I would call it in code as

console.writeln(Resources.jimstring)

How to put a placement variable ( xmlscript ) (is that what they call?) In the resource string in console.writeln?

Thanks,

Bean

+7
c # resources
source share
2 answers

As Jeff Johnson noted in his answer, this is basically the same as the original .WriteLine () console. A resource string is just a string. Therefore, you refer to the resource file and make the format.

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

  var newString = String.Format(resources.jimstring, xmlscript); 
+12
source share
 Console.WriteLine(Resources.jimstring, xmlscript); 

Console.WriteLine accepts additional formatting arguments that replace {0} in your Resources.jimstring line.

Additional information here: http://msdn.microsoft.com/en-us/library/828t9b9h.aspx

+7
source share

All Articles