本文介绍了创建正确的路径,将左右部分与左右部分连接时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在很大程度上简化了问题,这是示例代码:

I have simplified in a big way the problem and here is the sample code:

string outputString = string.Empty;
string joinOutputString = string.Empty;
string pathOutputString = string.Empty;

string[] myStrings = new string[4];
myStrings[0] = "First entry";
myStrings[1] = "اول";
myStrings[2] = "دوم";
myStrings[3] = "Last entry";

StringBuilder sb = new StringBuilder();

for (int i = 0; i < myStrings.Length; i++)
{
    joinOutputString = string.Join(@"\", joinOutputString, myStrings[i]);
    outputString = string.Format(@"{0}{1}\", outputString, myStrings[i]);
    pathOutputString = System.IO.Path.Combine(pathOutputString, myStrings[i]);
    sb.Append(string.Format(@"{0}\", myStrings[i]));
}

循环末尾所有字符串和StringBuilder的最终值为:

The final value of all strings and StringBuilder at the end of the loop is:

第一次输入\اول\دوم\最后输入\

First entry\اول\دوم\Last entry\

代替

第一个条目\دوم\اول\最后一个条目\

First entry\دوم\اول\Last entry\

从右向左中间的部分翻转为一个

The middle right to left section is flipped as one unit.

谢谢您的时间。

推荐答案

您有一个比迪字符串(一个包含LTR和RTL字符的字符串),. NET在输出该字符串时在LTR和RTL模式之间切换。标点符号被认为是弱点,并继续使用当前处于活动状态的任何方向。因此,您输出一个LTR字符串(第一个条目),然后输出一串RTL字符(myString [1]中的3个字符串,以及myString [2]中的 \ + 3个字符),然后是LTR字符串(最后条目) 。

You have a bidi string (a string containing both LTR and RTL characters) and .NET is switching between LTR and RTL modes when outputting the string. Punctuation is considered "weak" and continues using whatever direction is currently active. So you output a LTR string ("First entry") followed by a string of RTL characters (3 from myString[1] + "\" + 3 from myString[2]) followed by a LTR string ("Last entry").

myString [0](打印LTR),然后是myString [1](打印RTL),然后是myString [2](打印RTL),然后是myString [3](打印LTR) )

myString[0] (printed LTR) then myString[1] (printed RTL) then myString[2] (printed RTL) then myString[3] (printed LTR)

请注意,整个中间字符串(由myString [1] + \ + myString [2]组成)均已打印RTL,因此与您的期望相反。您可以添加伪强LTR标记(Unicode字符0x200E)来强制更改方向。

Note that the entire middle string (composed of myString[1] + "\" + myString[2]) is printed RTL and hence transposed from your expectation. You can add a pseudo-strong LTR mark (Unicode character 0x200E) to force the direction change.

在您的代码中:

joinOutputString = string.Join("\\\x200E", joinOutputString, myStrings[i]);

请注意,\是转义的\,而x200E是伪强LTR标记。

Note the \ is an escaped \ and \x200E is the pseudo-strong LTR mark.

这篇关于创建正确的路径,将左右部分与左右部分连接时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:30