Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

VB
<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
Posted
Updated 13-Jun-17 2:05am
Comments
Richard MacCutchan 9-Jun-17 6:32am    
Try putting the ellipsis first: Return "..." & Left(strArg, len).

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)[^]
 
Share this answer
 
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"
C#



js supported and this onec# code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900