String Operations

Mmm I am quite unsure how this line works. Is the Recordset Field defined as UTF first and then converted to WindowsLatin1 or vice verca?

x = DefineEncoding(rs.Field("AnyFieldname").getString, Encodings.UTF8).ConvertEncoding(Encodings.WindowsLatin1)

well, better write like this:

dim s as string = rs.Field("AnyFieldname").StringValue if s.encoding = nil then if encodings.UTF8.IsValidData(s) then s = defineEncoding(s, encodings.UTF8) else s = defineEncoding(s, Encodings.WindowsLatin1) end if end if

This way you use the encoding which is there.

ConvertEncoding(Encodings.WindowsLatin1) is normally not useful in Xojo apps which use UTF-8 for anything.
So the WindowsLatin1 is probably converted to UTF-8 anyway on the next string operation.

You’re right, this is a more defensive approach. I’ll check this out. And FYI I am already using everything in UTF8 but I need Latin1 encoded strings for another Software accessing my data (CTI software: http://www.c4b.de). Unfortunately they cannot deal with encodings as far as I see… so I have to adjust my code…

You have it backward. Define first. Convert after. ConvertEncoding on an incorrectly defined string will damage the data.