[.Net] File.ReadAllText - UTF8Encoding

LucaMs

Expert
Licensed User
Longtime User
Is it enough use UTF8Encoding.Default to read a text file (.txt) as in the title?

Will make it possible to read special characters such as accents Germans, for example, or Cyrillic, etc.?
 

LucaMs

Expert
Licensed User
Longtime User
no, it is not enough!

For Cyrillic, for example, I have to use:
IO.File.ReadAllText(FullFileName, System.Text.Encoding.GetEncoding(1251))


(Why "Strike-Through" is not next to Bold-Italic-Underline?)

1251 is a "Code page"
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I need to use that statement (...GetEncoding(1251) but because my Default is not for Cyrillic chars!
Maybe on a russian PC, UTF8Encoding.Default works.

So, I still need an answer :)
 

LucaMs

Expert
Licensed User
Longtime User
It should be in the chit chat forum as it is not a B4A question (should we accept PHP, C, Assembler and other languages in the B4A forum?)

You could search on Google: "site:basic4ppc.com PHP Questions". ;)

You're right but, as you can see, posting in b4a questions I have received no responses and in Chit Chat it would be read much less.
The name, "Chit Chat", suggests "forum of things not related to programming".

Additionally, this problem also exists reading a file using other languages (b4a, b4j and b4i).

However, it does not matter, since the only answers were these yours.
 

LucaMs

Expert
Licensed User
Longtime User
The answer to your question is that it depends. You should use the same encoding as the encoding that was used when the file was saved.

I suppose that if a Russian citizen save a text file using NotePad this file will be encoded in a different way from that of the Italian and the encoding depends on the settings on your PC.
Should I try to detect what is the file encoding?

UTF8 supports all characters.

This seems sufficient but, if so, other types of coding should not be necessary.


Thanks for the reply, Erel.

Maybe I will wait for the user complaints :D.

Or I will make some attempt in the Chinese Forum :D


[Speedy (DonManfred) how are your umlaut? :)]
 

LucaMs

Expert
Licensed User
Longtime User
There is no simple way to detect the encoding. The same binary data can be decoded correctly in many encodings.

So, it is an hard question.

I would like to ask how this is done with html:

如果你还没有安装Basic4android和Java SDK,请先参照后面的链接里面的安装和配置方法:
http://www.basic4ppc.com/forum/basic...droid-sdk.html

在这个教程里面,我们将建立一个新的AVD (Android Virtual Device)并生成模拟器实例. 然后我们将建立一个简单的程序,这个程序将显示一个简单的信息框,并写一个信息到日志里.
你也可以通过IDE 连接到一个真正的设备上:
使用ADB连接你的设备
使用B4A-Bridge连接你的设备
常见的问题解决列在在本教程的后面. 如果你碰见的问题没在列表或者无法解决的话, 请与 [email protected] 联系


but I do not.

1) because it may be different;
2) because you ask me to open a new thread :D:D:D
 

LucaMs

Expert
Licensed User
Longtime User
On the other hand, the codings allowed by NotePad are these:

upload_2014-11-16_13-24-38.png


So it will be enough that I studies and applies these.
 

LucaMs

Expert
Licensed User
Longtime User
Resolved:

I used a chinese .bas file as a template for my sw, without making any changes to it, and I can perfectly... read Chinese texts :D.


Thanks again, Erel
 

LucaMs

Expert
Licensed User
Longtime User
B4A saves files encoded with UTF8. If you are using UTF8 then the file will be loaded correctly. Make sure to also save it with UTF8.

I used ReadAllLines and ReadAllText (VB.Net) without passing the argument Encoding and, at least for the German character, now it works.

Thanks, Erel
 
Top