我正在尝试组合/连接来自字符串的阿拉伯字母。
这种语言和其他语言的问题在于每个字母有 4 种显示方式:独立、声母、中音和韵母。
我已经阅读了很多有关该问题的内容,但不明白是否有解决方案。
我有这样的文字:мурда(意思是“Marhaba” - 你好),它是从右向左阅读的。
我正在为另一个程序开发一个插件,它为我提供了相同的字符串连接,但向后连接,如下所示:??????(如果我们从 LTR 读取它,没关系,但它应该是 RTL),所以我将字符分开并反转它们,但是当我将它们绘制在屏幕上(图形应用程序)时,它们会以独立的形式显示,如下所示:从 RTL 读取良好,但未连接。 所以我尝试了很多方法让它们以连接的形式显示在屏幕上,但没有成功,有没有一种简单的方法可以在显示时用来连接它们?
提前致谢。
我的反转字母的代码是:
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(stringFromApp);
List<string> elements = new List<string>();
while (enumerator.MoveNext())
elements.Add(enumerator.GetTextElement());
elements.Reverse();
string reversed = string.Concat(elements);
App.textObject.text = reversed;
// Specify Arabic script Unicode ranges
const int arabicStart = 0x0600;
const int arabicEnd = 0x06FF;
private char MapArabicCharacter(char originalChar, int charIndex, int firstCharIndex, int lastCharIndex)
{
// Check if the character is Arabic
if (IsArabicCharacter(originalChar))
{
// If the character is the first or last character in the text, return the isolated form
if (charIndex == firstCharIndex || charIndex == lastCharIndex)
{
// Return the isolated form of the character
// Note: This is a simplified approach and may not handle all cases correctly
return GetIsolatedForm(originalChar);
}
}
// If the character is not Arabic or does not meet the above conditions, return the original character
return originalChar;
}
// Function to check if a character is Arabic
private bool IsArabicCharacter(char c)
{
// Check if the character falls within the Arabic Unicode range
return (c >= arabicStart && c <= arabicEnd);
}
// Function to get the isolated form of an Arabic character
private char GetIsolatedForm(char c)
{
// Add logic to return the isolated form of the character
// This is a simplified example and may not handle all cases correctly
// For demonstration purposes, we'll just return the character itself
return c;
}
并使用它
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(stringFromApp);
List<char> mappedChars = new List<char>();
int charIndex = 0;
int lastCharIndex = stringFromApp.Length - 1;
while (enumerator.MoveNext())
{
char originalChar = enumerator.GetTextElement()[0];
char mappedChar = MapArabicCharacter(originalChar, charIndex, 0, lastCharIndex);
mappedChars.Add(mappedChar);
charIndex++;
}
mappedChars.Reverse();
string reversed = new string(mappedChars.ToArray());
App.textObject.text = reversed;