如何截断urdu语言中的字符串 [英] How to truncate string in urdu language

查看:83
本文介绍了如何截断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 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 a Unicode character table which uses 2 bytes to describe each Urdu character instead of 1 byte when using ANSI or ASCII character tables. The simpliest solution would be to double the value of the len parameter and use Right instead of Left function. Also place the three points left of the truncated string as Richard suggested. For a really correct handling you should make use of the Encoding 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"






支持js ,这一个 c#代码


这篇关于如何截断urdu语言中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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