我如何才能使用希伯来语替换此字符串呢? [英] How can I get this string replacement in hebrew to work?
本文介绍了我如何才能使用希伯来语替换此字符串呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用希伯来语字符串替换此占位符.但不幸的是,字符串替换无法正常工作.看来在希伯来语字符串中根本找不到占位符字符串.
I would like to replace this placeholders in a hebrew string. But unfortunately the string replacement does not work. It looks like the placeholder string cannot be found at all within the hebrew string.
[Test]
public void Fancy_placeholder_should_be_replaced()
{
const string input = "(השדה @%1$ קצר מדי (@%2$ תווים לפחות";
const string expected = "(השדה {0} קצר מדי ({1} תווים לפחות";
var dummy = input.Replace("%2$@", "{1}");
dummy = dummy.Replace("%1$@", "{0}");
Assert.AreEqual(expected, dummy);
}
如何在这里进行替换工作?
How can I make replacement work here?
推荐答案
从右至左的问题弄乱了结果,特别是"@"字符.将您的功能修改为:
It is the right-to-left issue that messes up the results, in specific, it is the "@" char. modify your function to:
public void Fancy_placeholder_should_be_replaced()
{
const string input = "(השדה @%1$ קצר מדי (@%2$ תווים לפחות";
const string expected = "(השדה {0} קצר מדי ({1} תווים לפחות";
var formatted = input.Replace("@%2$", "{1}");
formatted = formatted.Replace("@%1$", "{0}");
bool same2 = expected == formatted;
Assert.AreEqual(expected, formatted);
}
和田田!它有效...
And tada! it works...
这篇关于我如何才能使用希伯来语替换此字符串呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文