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.
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)
: "");,
Demo: .NET Fiddle Example
Similar issues:
incorrect right to left concatenation english and Arabic
Problem creating correct path concatenating left to right with right to left sections
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…