如何截断urdu语言中的字符串 [英] How to truncate string in urdu language
本文介绍了如何截断urdu语言中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a function that truncate a string after givin lenght ,
thats work fine when I use English language,but when I switched to Urdu by changing globalization setting in window,then it does not work expectedly,like in the following picture,I want (...) on opposite side
图片在此澄清点击我请
我尝试过:
picture are here for clarification Click Me PLEASE
What I have tried:
<pre>Public Shared Function StringTruncate(ByVal strArg As String, ByVal len As String) As String
If Trim(strArg).Length > len Then
Return Left(strArg, len) & "..."
Else
Return strArg
End If
End Function
推荐答案
您的问题的原因是编码和读取方向(RightToLeft
)。当更改为Urdu时,系统使用Unicode
字符表,当使用ANSI $ c时,该字符表使用2个字节来描述每个Urdu字符而不是1个字节$ c>或
ASCII
字符表。最简单的解决方案是将len
参数的值加倍,并使用右
而不是左
功能。同样放置截断字符串左边的三个点,如理查德建议的那样。要获得真正正确的处理,您应该使用VB.NET中的编码
函数。
也许这个链接可以帮助您理解:如何转换/显示vb.net中的unicode字符串| Nishant Pant的技术博客 [ ^ ]
编码函数请看这里:Encoding-Klasse(System.Text) [ ^ ]
THe reason for your problem is the encoding and the read direction (RightToLeft
). When changing to Urdu the system uses aUnicode
character table which uses 2 bytes to describe each Urdu character instead of 1 byte when usingANSI
orASCII
character tables. The simpliest solution would be to double the value of thelen
parameter and useRight
instead ofLeft
function. Also place the three points left of the truncated string as Richard suggested. For a really correct handling you should make use of theEncoding
functions in VB.NET.
Maybe this link can help for your understanding: How to convert/display a unicode string in vb.net | Nishant Pant's Techie Blog[^]
For encoding functions have a look here: Encoding-Klasse (System.Text)[^]
After one day struggle I have found js and C# solution of language detection problem. Here is the code through which we can check any language that user input in the field.
LanguageDetector ld = new LanguageDetector();
string lanCode = ld.Detect("this is an example text in english");
if (lanCode == null) throw new Exception("Cannot detect language");
string languageNaturalName = ld.GetLanguageNameByCode(lanCode); //returns "English" for language code "en"
这篇关于如何截断urdu语言中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文