使用string.Format()连接Concat阿拉伯和英语字符串 [英] Concat arabic and english string with string.Format()

查看:263
本文介绍了使用string.Format()连接Concat阿拉伯和英语字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用concat两个字符串遇到一些麻烦.

Have some trouble with concat two string.

return string.Format("{0}{1}{2}",
            IdWithSubType,

            ExtraInfo.Any(info => info.InfoType == UniExtraInfoType.Alias)
            ? string.Format(" ({0})", string.Join(",", ExtraInfo.First(info => info.InfoType == UniExtraInfoType.Alias).Info))
            : "",

            Context != null
            ? string.Format(" ({0})", Context.IdWithSubType)
            : "");

当IdWithSubType,extrainfo和context具有拉丁或基里尔符号时是可以的,但是IdWithSubType可以是阿拉伯语,并且与之连接是错误的. 例如100252575)طائراتهليكوبت@ vk.com) 阿拉伯符号和其他符号混合在一起,但是我需要类似这里是阿拉伯字符串"(100252575@vk.com.如果使用String.Format解决此问题,那就太好了.希望对您有所帮助.谢谢

it's ok when IdWithSubType, extrainfo and context has latin or kirillic symbols, but IdWithSubType can be arabic, and concat with that is wrong. e.g.100252575)طائرات هليكوبت@vk.com) arabic and other symbols mixed, but i need something like "here arabic string" (100252575@vk.com. it would be great if this problem have solve with String.Format. Hope for your help. Thank you

推荐答案

可能没有编码问题出现,只是RTL(从右到左)字符串作为LTR(从左到右)字符串的一部分遵循排列方式

It's likely no encoding issues appear there, just how RTL (right-to-left) string follows arrangement as part of LTR (left-to-right) string.

双向格式化中通常使用2个字符来标记LTR和RTL部分,分配为 0x200e (LTR)& 0x200f (RTL).在这种情况下,请使用0x200e标记RTL部分的结尾(阿拉伯语)并开始LTR部分:

There's 2 characters which commonly used in bidirectional formatting to mark either LTR & RTL part, assigned as 0x200e (LTR) & 0x200f (RTL). In this case, use 0x200e to mark end of RTL part (in Arabic) and starting LTR part:

string leftToRight = ((char)0x200E).ToString();

// using string.Format
return string.Format("{0}{1}{2}{3}",
            IdWithSubType,
            leftToRight,

            ExtraInfo.Any(info => info.InfoType == UniExtraInfoType.Alias)
            ? string.Format(" ({0})", string.Join(",", ExtraInfo.First(info => info.InfoType == UniExtraInfoType.Alias).Info))
            : "",

            Context != null
            ? string.Format(" ({0})", Context.IdWithSubType)
            : "");,

// alternative: using string.Join
return string.Join(leftToRight, IdWithSubType,
            ExtraInfo.Any(info => info.InfoType == UniExtraInfoType.Alias)
            ? string.Format(" ({0})", string.Join(",", ExtraInfo.First(info => info.InfoType == UniExtraInfoType.Alias).Info))
            : "",

            Context != null
            ? string.Format(" ({0})", Context.IdWithSubType)
            : "");,

演示: .NET小提琴示例

类似的问题:

英语和阿拉伯语从右到左串联不正确

>创建正确的问题路径从左到右,从右到左连接起来

这篇关于使用string.Format()连接Concat阿拉伯和英语字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆