PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV Mobile 2024 → ansi or unicode format
ansi or unicode format
Started by JOHNKEN, Nov., 20 2014 2:41 PM - 17 replies
Registered member
26 messages
Posted on November, 20 2014 - 2:41 PM
How to detect if the text file you are accessing/opening is ansi or unicode format?
Posted on November, 20 2014 - 3:04 PM
Hi

When you load it in a buffer variable, the first 2 bytes contains a
specific value in UNICODE mode. Be careful that there are several
variants of Unicode (little endian, big endian...), so there may be
several different header value to test.

You can of course check that out by using an Hexadecimal editor on your
files

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 11/20/2014 8:41 AM, JOHNKEN wrote:
How to detect if the text file you are accessing/opening is ansi or
unicode format?
Registered member
4,613 messages
Posted on November, 20 2014 - 3:20 PM
Procedure WS_Android_IOS_HTTPGetResult()

// Variable
bufResHTTP is Buffer
sHTTPResult is string

// Retrieves the result of the query
bufResHTTP = HTTPGetResult(httpResult)

// Result in UTF8 em iOS Apple
IF IniOSMode() = True OR IniOSSimulatorMode() = True OR IniOSEmulatorMode() = True
IF StringCount(bufResHTTP, “ISO-8859-1, IgnoreCase) = 0 THEN
sHTTPResult = UTF8ToString(bufResHTTP)
ELSE
sHTTPResult = AnsiToUnicode(bufResHTTP)
END
ELSE IF InAndroidMode() = True OR InAndroidSimulatorMode() = True OR InAndroidEmulatorMode() = True
// Result in Android
sHTTPResult = bufResHTTP
END

RESULT sHTTPResult
Registered member
4,613 messages
Posted on November, 20 2014 - 3:28 PM
JOHNKEN

I work with Windev Mobile set IN [x] ANSI GLOBAL project

I had to make this overall Procedure for making the identification was coming up the RETURN of the HTTPRequest with Unicode OR ANSI IN HTTPGetResult, I stopped using the standard command after the HTTPRequest AND I Use mine AND have had success.

Using my example Above Procedure:

url = "br.linkedin.com/in/adrianoboller"

ok is boolean = HTTPRequest (Url)

IF ok = True

RETURN is string = WS_Android_IOS_HTTPGetResult()

END

Came No more Japanese, Korean OR Chinese code AND thus... rssss.... :)
Registered member
26 messages
Posted on November, 20 2014 - 4:08 PM
Thanks for the reply guys...

another question, Im using windows ce device and want to read a text file copied to the device.
how will i determine automatically if that file is in ansi or unicode format.
Registered member
4,613 messages
Posted on November, 20 2014 - 9:39 PM
Same Technique

IF StringCount(bufResHTTP, “ISO-8859-1, IgnoreCase) = 0 THEN
RESULT = UTF8ToString(TextBuffer)
ELSE
RESULT = AnsiToUnicode(TextBuffer)
END
Registered member
4,613 messages
Posted on November, 20 2014 - 9:40 PM
Procedure LE_ASCII(LOCAL ArquivoTxt)

//Le arquivo texto

// Declare the variables
PathFile is string = ArquivoTxt
IdFile, ResCloseFile, FileID, NumeroLinha is int
Line is string

// Open the file
FileID = fOpen(PathFile,foReadWrite)
IF IdFile = -1 THEN
Error(ErrorInfo(errMessage))
ELSE

//Converte de Unicode para Ansi
Line = UnicodeToAnsi(fReadLine(FileID))

//Linha 1
NumeroLinha = 1
//Info("Linha:" + NumeroLinha, Line)

WHILE Line <> EOT AND Line <> ""

//Proxima linha
NumeroLinha += 1
Line = fReadLine(FileID)
//Info("Linha:" + NumeroLinha, Line)

END
IF Line = "" THEN Error(ErrorInfo(errMessage))
IF Line = EOT THEN Info("Final do Arquivo.")
ResCloseFile = fClose(IdFile)
IF ResCloseFile = -1 THEN
//Error(ErrorInfo(errMessage))
END

END
Registered member
4,613 messages
Posted on November, 20 2014 - 9:44 PM
Change your project globally to ANSI

P (Big Yellow) -> popup Mouse Right -> Project Description -> Down Button: [ DESCRIBING THE CURRENT CONFIGURATION ] -> Guia Aba: UNICODE -> Check [x] ANSI -> OK -> OK

Re-test code... ok
Posted on November, 20 2014 - 9:54 PM
Hi

in what exactly is that another question? This looks exactly like the
one I already answered to...

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

NEW: WXReplication, your open source replication system is available on
my web site!!!
WXShowroom.com: Show your projects!
More information on http://www.fabriceharari.com


On 11/20/2014 10:08 AM, JOHNKEN wrote:
Thanks for the reply guys...
another question, Im using windows ce device and want to read a text
file copied to the device.
how will i determine automatically if that file is in ansi or unicode
format.
Registered member
26 messages
Posted on November, 21 2014 - 5:31 AM
thanks adrianoboller,
got it already
Registered member
4,613 messages
Posted on November, 21 2014 - 1:27 PM
JOHNKEN

But he succeed?

If not send me a mini project to try to help you...

Att

Adriano
Registered member
26 messages
Posted on November, 21 2014 - 3:25 PM
Hi Adriano,

I did it but its separate process for ansi and unicode file.

here is my sample project
https://www.dropbox.com/s/obuuq0q4pu5oqlh/AnsiUnicode.rar…
Registered member
4,613 messages
Posted on November, 22 2014 - 12:50 PM
Ok I will look today and give you a return
Max until Monday

:merci:
Posted on February, 19 2022 - 1:31 PM
If you need to migrate your ansi file to unicode, then there is a manual method where you have to configure your ansi to your unicode via Import/export feature and then import your ansi file. You can also transfer your file through ansi To unicode Migration Tool and transfer your data easily.

Visit at : https://www.osttopstapp.com/ansi-to-unicode-pst.html
Registered member
56 messages
Posted on February, 23 2022 - 10:43 AM
hi,
I tried to use your procedure for maneg a respons from a websevice that has been giving me problems for some time to IOS, your solution works in the emulator but not on a real IOS smartphone.
Have you ever tested it in production?

Procedure WS_Android_IOS_HTTPGetResult()

// Variable
bufResHTTP is Buffer
sHTTPResult is string

// Retrieves the result of the query
bufResHTTP = HTTPGetResult(httpResult)

// Result in UTF8 em iOS Apple
IF IniOSMode() = True OR IniOSSimulatorMode() = True OR IniOSEmulatorMode() = True
IF StringCount(bufResHTTP, “ISO-8859-1”, IgnoreCase) = 0 THEN
sHTTPResult = UTF8ToString(bufResHTTP)
ELSE
sHTTPResult = AnsiToUnicode(bufResHTTP)
END
ELSE IF InAndroidMode() = True OR InAndroidSimulatorMode() = True OR InAndroidEmulatorMode() = True
// Result in Android
sHTTPResult = bufResHTTP
END

RESULT sHTTPResult


I haven't found a solution to my problem for months and your help would be greatly appreciated.

thanks
Message modified, February, 23 2022 - 10:43 AM
Registered member
4 messages
Posted on February, 25 2022 - 1:41 PM
the first 2 bytes contains a
specific value in UNICODE mode. Be careful that there are several
variants of Unicode (little endian, big endian...), so there may be
several different header value to test.

You can of course check that out by using an Hexadecimal editor on your
files.
Registered member
4 messages
Posted on February, 25 2022 - 1:45 PM
Be careful that there are several
variants of Unicode (little endian, big endian...), so there may be
several different header value to test.

You can of course check that out by using an Hexadecimal editor on your
files
Registered member
4,613 messages
Posted on December, 04 2025 - 12:54 AM
No WINDEV Mobile, a mudança de Unicode para ANSI pode ser feita principalmente nas configurações do projeto, para alterar o comportamento padrão das strings em tempo de execução. Isso é útil para compatibilidade com serviços ou arquivos que exigem ANSI, mas lembre-se de que o WINDEV Mobile usa Unicode por padrão, e alterações podem afetar o tratamento de caracteres especiais (como em idiomas asiáticos). Aqui vai o passo a passo principal, baseado em documentações e fóruns oficiais:


Configuração Global no Projeto

Para alternar todo o projeto para usar strings ANSI em runtime:
1 Clique com o botão direito no projeto (no painel principal, representado pelo ícone amarelo grande “P”).
2 Selecione “Descrição do Projeto” (Project Description).
3 Na janela que abre, vá até a aba “Unicode”.
4 Escolha a opção “Usar strings ANSI em tempo de execução” (Use ANSI strings at runtime).
5 Confirme as alterações e recompile/teste o projeto, pois isso afeta globalmente o código. 10 5 3
Essa configuração resolve problemas como caracteres corrompidos em respostas HTTP ou arquivos de texto, especialmente em dispositivos reais (iOS ou Android), onde emuladores podem se comportar diferente. 10

Conversões Pontuais via Funções
Se você não quiser alterar o projeto inteiro, use funções para converter strings específicas:
• UnicodeToAnsi(): Converte uma string Unicode para ANSI. Exemplo: sANSI = UnicodeToAnsi(sUnicode).
• AnsiToUnicode(): O inverso, para converter ANSI para Unicode. Essas funções são ideais para integrações com web services ou arquivos que não suportam Unicode, como em chamadas HTTP onde você carrega o resultado em um buffer e converte com base na plataforma (ex.: UTF8ToString para iOS se não for ISO-8859-1). 0 1 10

Dicas Adicionais de Usuários
• Verifique o cabeçalho do arquivo (primeiros dois bytes) com um editor hexadecimal para confirmar se é Unicode (ex.: FF FE para UTF-16 LE). Em código, carregue em um buffer e teste programaticamente.
• Em iOS, conversões podem falhar em dispositivos reais mesmo funcionando no emulador – teste exaustivamente.
• Para arquivos locais (ex.: em Windows CE), use fOpen e leia linhas convertendo com UnicodeToAnsi.
• Há exemplos de projetos de amostra compartilhados em fóruns para lidar com ANSI/Unicode separadamente. 10
Se precisar de mais detalhes ou código específico, forneça o contexto do seu projeto (versão do WINDEV Mobile, plataforma alvo)!

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/