I do not know if someone is already aware of an error in the LEN() command in FreeBasic?
If you use strings with international characters (like German umlauts or French accents) you get wrong results with the LEN() command.
Just to show it, I have created a small test program:
Code: Select all
' Short test program demonstrating the wrong results of the
' len() command in FreeBasic
' -----------------------------------------------------------
' ....+....1....+...
dim germanstring as string = "Märchenkönigsgrüße" 'length=18
' ....+....1....+..
dim danishstring as string = "Rødgrød med fløde" 'length=17
' ....+....1....+
dim turkishstring as string = "Bir çay lütfen!" 'length=15
' ....+....1....+...
dim frenchstring as string = "Académie Française" 'length=18
dim as integer germanlen, danishlen, turkishlen, frenchlen
print "Test of international strings with FreeBasic"
print "--------------------------------------------"
germanlen = len(germanstring)
print "Output of German string: " + germanstring
print "Length of German string: "; germanlen
danishlen = len(danishstring)
print "Output of Danish string: " + danishstring
print "Length of Danish string: "; danishlen
turkishlen = len(turkishstring)
print "Output of Turkish string: " + turkishstring
print "Length of Turkish string: "; turkishlen
frenchlen = len(frenchstring)
print "Output of French string: " + frenchstring
print "Length of French string: "; frenchlen
- Test of international strings with FreeBasic
--------------------------------------------
Output of German string: Märchenkönigsgrüße
Length of German string: 22
Output of Danish string: Rødgrød med fløde
Length of Danish string: 20
Output of Turkish string: Bir çay lütfen!
Length of Turkish string: 17
Output of French string: Académie Française
Length of French string: 20
If I do the same in other languages, e.g. Mono Basic, the results are correct.
To prove it, here's another small test program written in Mono Basic:
Code: Select all
Public Class Application
Public Shared Sub Main()
' ....+....1....+...
dim germanstring as string = "Märchenkönigsgrüße" 'length=18
' ....+....1....+..
dim danishstring as string = "Rødgrød med fløde" 'length=17
' ....+....1....+
dim turkishstring as string = "Bir çay lütfen!" 'length=15
' ....+....1....+...
dim frenchstring as string = "Académie Française" 'length=18
dim germanlen, danishlen, turkishlen, frenchlen as integer
System.Console.WriteLine("Test of international strings with Mono Basic")
System.Console.WriteLine("---------------------------------------------")
germanlen = germanstring.length()
System.Console.WriteLine("Output of German string: " + germanstring)
System.Console.WriteLine("Length of German string: " + germanlen.ToString())
danishlen = danishstring.length()
System.Console.WriteLine("Output of Danish string: " + danishstring)
System.Console.WriteLine("Length of Danish string: " + danishlen.ToString())
turkishlen = turkishstring.length()
System.Console.WriteLine("Output of Turkish string: " + turkishstring)
System.Console.WriteLine("Length of Turkish string: " + turkishlen.ToString())
frenchlen = frenchstring.length()
System.Console.WriteLine("Output of French string: " + frenchstring)
System.Console.WriteLine("Length of French string: " + frenchlen.ToString())
End Sub
End Class
- Test of international strings with Mono Basic
---------------------------------------------
Output of German string: Märchenkönigsgrüße
Length of German string: 18
Output of Danish string: Rødgrød med fløde
Length of Danish string: 17
Output of Turkish string: Bir çay lütfen!
Length of Turkish string: 15
Output of French string: Académie Française
Length of French string: 18
Both programs (FreeBasic and Mono Basic) were executed on the same box running Ubuntu 16.04LTS.
I also tried the FreeBasic test program under Window which gives me the same (wrong) results.
Is there a way to get the correct string lengths (=number of displayed characters) in FreeBasic?
Thanks!
//haegar