B4J Question [BANanoFetch] How can I apply text encoding e.g. ISO-8859-1

sdleidel

Active Member
Licensed User
Longtime User
Ok…
I use the SDUI Table to load a file for Import from Customer.
But How I can convert the charset from the file?
My Customer can Not Change it…
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
A quick google search reveals the .Text of Response from a Fetch is always decoded to utf-8, but it is pretty simple to decode the ArrayBuffer yourself:

Something like:
B4X:
Dim response As BANanoFetchResponse
Dim error As BANanoObject
Dim buffer() As BANanoObject
 
Dim fetch As BANanoFetch
Dim options As BANanoFetchOptions
options.Method = "GET"
options.Initialize
fetch.Initialize("https://yourcall",options)
fetch.Then(response)
        fetch.Return(response.ArrayBuffer)
fetch.Then(buffer)
        Dim decoder As BANanoObject
        decoder.Initialize2("TextDecoder", "iso-8859-1")
        Dim text As String = decoder.RunMethod("decode", buffer).Result
        Log(text)
fetch.Else(error)
        Log(error)
fetch.End

Alwaysbusy
 
Upvote 0
Top