C#如何将放置变量添加到资源字符串中

sco*_*eep 11 c# resources

这应该很容易,但找不到任何解释它.

说我在console.writeln上写了一些东西,比如:

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

假设我想将字符串"Jim is .."转换为全局resource.resx中的资源字符串.这将是:

jimstring jim is a {0}

我会在代码中将其称为

console.writeln(Resources.jimstring)

如何将placement variable(xmlscript)(这是它们被称为?)放入console.writeln中的资源字符串中?

谢谢,

短发

Sai*_*udo 18

正如杰夫约翰逊在他的回答中提到的,它基本上与原始的Console.WriteLine()完全相同.资源字符串只是一个字符串.因此,您引用资源文件并执行格式化.

如果你需要它而不是Console,你可以使用String.Format():

  var newString = String.Format(resources.jimstring, xmlscript);
Run Code Online (Sandbox Code Playgroud)


jjx*_*tra 8

Console.WriteLine(Resources.jimstring, xmlscript);
Run Code Online (Sandbox Code Playgroud)

Console.WriteLine采用其他格式化参数来替换Resources.jimstring字符串中的{0}.

更多信息:http://msdn.microsoft.com/en-us/library/828t9b9h.aspx