解决vb读取带汉字文本文件乱码问题
www.dimcax.com
解决vb读取带汉字文本文件乱码问题
不知大家有没有这种情况,用vb读取带汉字的文件。读出的是乱码。经过我几天用google上网搜。终于找到了解决方法。请看原代码:
public function readfile(byval filename as string) as string()
dim byt() as byte
dim int as integer = 0
dim str() as string
dim fs as filestream
dim br as binaryreader
fs = new filestream(filename, filemode.open)
br = new binaryreader(fs)
while fs.position < fs.length
redim preserve byt(int)
byt(int) = br.readbyte
int = int + 1
end while
br.close()
fs.close()
int = 0
dim int1 as integer = 0
redim preserve str(int1)
while int < byt.length
if byt(int) < 128 then
if byt(int) <> 13 and byt(int) <> 10 then
str(int1) = str(int1) & chr(byt(int))
end if
if byt(int) = 13 or byt(int) = 10 then
int = int + 1
'if str(int1).length <> 0 then
int1 = int1 + 1
redim preserve str(int1)
'end if
end if
int = int + 1
else
str(int1) = str(int1) & chr(256 * byt(int) + byt(int + 1))
int = int + 2
end if
end while
return str
end function
lisp vba arx .net开发都会一点。可惜都不精。希望和大家共同学习进步。
自已顶一下。此帖不能沉下去。
lisp vba arx .net开发都会一点。可惜都不精。希望和大家共同学习进步。