Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Foreign Languages > Other languages > Chinese Forum
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4PPC怎么从文本文件读取和保存中文信息?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-19-2009, 02:18 PM
Newbie
 
Join Date: Jan 2009
Posts: 1
Default Basic4PPC怎么从文本文件读取和保存中文信息?

我试了一下,出来的都是?号,不知道是怎么回事。
Reply With Quote
  #2 (permalink)  
Old 10-20-2009, 03:15 AM
Junior Member
 
Join Date: Jul 2009
Posts: 30
Default

你将要读取的文本文件“另存为”——“编码”——选择“utf-8”

这样就可以成功读取中文的文本文件了


读取文本文件的代码是:

Sub Globals
'Declare the global variables here.

End Sub

Sub App_Start
Form1.Show
FileOpen(c,"text.txt",cRead)
TextBox1.Text = FileReadToEnd(c)
FileClose(c)
End Sub
Reply With Quote
  #3 (permalink)  
Old 11-10-2009, 05:21 PM
Newbie
 
Join Date: Nov 2009
Location: NanPing
Posts: 7
Send a message via MSN to redsuntv
Default

我也遇到这个问题。希望读出的中文能显示在一个文本框里, 但遇到中文都就问号(?)。
谁知道如何解决?
Reply With Quote
  #4 (permalink)  
Old 11-11-2009, 02:34 AM
Junior Member
 
Join Date: Jul 2009
Posts: 30
Default

晕倒,我不是给了解决方法了吗?
Reply With Quote
  #5 (permalink)  
Old 11-11-2009, 09:16 AM
Newbie
 
Join Date: Nov 2009
Location: NanPing
Posts: 7
Send a message via MSN to redsuntv
Default

Quote:
Originally Posted by jeffrey8227 View Post
晕倒,我不是给了解决方法了吗?
我只是想读出来, 显示在文本框或列表框(listbox)里。
Reply With Quote
  #6 (permalink)  
Old 11-12-2009, 07:32 AM
Junior Member
 
Join Date: Jul 2009
Posts: 30
Default

你有没有仔细看过我给的代码?

有没有看到textbox1.text?
Reply With Quote
  #7 (permalink)  
Old 11-13-2009, 03:40 PM
Newbie
 
Join Date: Oct 2009
Location: changsha hunan prc
Posts: 6
Send a message via MSN to luby Send a message via Yahoo to luby
Default

Quote:
Originally Posted by jeffrey8227 View Post
你将要读取的文本文件“另存为”——“编码”——选择“utf-8”

这样就可以成功读取中文的文本文件了


读取文本文件的代码是:

Sub Globals
'Declare the global variables here.

End Sub

Sub App_Start
Form1.Show
FileOpen(c,"text.txt",cRead)
TextBox1.Text = FileReadToEnd(c)
FileClose(c)
End Sub
你说的另存为,是指要先将文本文件手工处理吗?可以不处理直接读出中文吗?
Reply With Quote
  #8 (permalink)  
Old 11-14-2009, 12:45 AM
Junior Member
 
Join Date: Jul 2009
Posts: 30
Default

Quote:
Originally Posted by luby View Post
你说的另存为,是指要先将文本文件手工处理吗?可以不处理直接读出中文吗?
你在创建这个文本文件的时候,不要保存为ANSI,直接保存为UTF-8就可以了

不单单是WM,移动设备基本上都是只认UTF-8编码,WM上少部分程序可以认ANSI,不过B4P不支持
Reply With Quote
  #9 (permalink)  
Old 11-14-2009, 01:04 AM
Newbie
 
Join Date: Oct 2009
Location: changsha hunan prc
Posts: 6
Send a message via MSN to luby Send a message via Yahoo to luby
Default

Quote:
Originally Posted by jeffrey8227 View Post
你在创建这个文本文件的时候,不要保存为ANSI,直接保存为UTF-8就可以了

不单单是WM,移动设备基本上都是只认UTF-8编码,WM上少部分程序可以认ANSI,不过B4P不支持
JEFFREY,你好!
谢谢你的及时回复
我算是个新手了,只是对这个感兴趣.
你提示的创建这个文件用UTF-8模式,我暂时还灭有找到好办法,我这个文件是这段代码创建的:
'RESPONSE ,REQUEST 为HTTP的OBJECT, READER,WRITER为BINNARY的OBJECT

Sub DownloadFile (LocalFile,URL)
Response.New1
Request.New1(URL)
Response.Value = Request.GetResponse
Msgbox("Download size: " & Response.ContentLength)
Reader.New1(Response.GetStream,True)
FileOpen(c1,LocalFile,cRandom)
Writer.New1(c1,False)
Dim buffer(4096) As byte
count = Reader.ReadBytes(buffer(),4096)
Do While count > 0
Writer.WriteBytes2(buffer(),0,count)
count = Reader.ReadBytes(buffer(),4096)
Loop
FileClose(c1)
Response.Close
Msgbox("File saved.")
End Sub
============
我暂时无法知道怎么用UTF-8的格式来写这个LOCALFILE

不过我今天早晨起来不甘心,寻找了一个笨办法来解决这个读乱码的问题:


Bitwise.New2(00936) '将BITWISE初始化为中文简体字符集的CodePage Encoding
FileOpen(c1,"Newtxt.txt",cRandom) '打开文件
reader.New1(c1,True) '读文件
length = reader.ReadBytes(buffer(), 4096) '读出的文件长度
string=bitwise.BytesToString(buffer(),0,length) '将读出的文件BYTES按照BITWISE的初始化代码转换字符集
Msgbox(string)
FileClose(c1)
===========
需要引入一个BITWISE的OBJECT,由它来将读出来的文件的BYTES转换为00936也就是简体 中文的字符集,运行结果总算通过.但是显得很别扭和笨拙
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
祝贺中文社区成立! aylhf Chinese Forum 1 11-13-2009 03:36 PM
请帮助:使用串口控件联接外置gps,怎样让程序自动搜索到gps所用的端口 TomCn Chinese Forum 0 01-06-2009 04:14 PM
中文社区人烟稀少!!! wtudx432 Chinese Forum 0 12-21-2008 01:54 PM
怎么都没有交流的?/ aa1025 Chinese Forum 0 12-13-2008 02:05 PM
恭喜中文社区成立 dlham Chinese Forum 0 09-26-2008 02:31 AM


All times are GMT. The time now is 08:28 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0