几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】解决vb读取带汉字文本文件乱码问题 (http://www.dimcax.com/hust/showthread.php?t=9972)

yang686526 2009-04-21 06:06 PM

【转帖】解决vb读取带汉字文本文件乱码问题
 
解决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开发都会一点。可惜都不精。希望和大家共同学习进步。


所有的时间均为北京时间。 现在的时间是 03:20 PM.