Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Decoding GB2312 in .NET Compact Framework

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge about "how to decode GB2312 in. NET Compact Framework". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

The code is as follows:

Imports System.TextImports System.IOModule Module1Module Module1 Sub Main()Sub Main() Dim sr As New StreamReader("D:gb2312.txt") Dim fs As New FileStream("D:gb2312.dat", FileMode.Create) Dim sw As New BinaryWriter(fs) For i As Integer = 1 To 70 sr.ReadLine() Next Do Until sr.EndOfStream Dim ss As String() = sr.ReadLine.Split Dim HEX As Short = CShort(Val(ss(1).Replace("0x", "&H"))) Dim offset As Integer = (CInt(Val(ss(0).Replace("0x", "&H"))) - &H2121) * 2 sw.BaseStream.Position = offset sw.Write(HEX) Loop sw.Close() End SubEnd Module

When using, subtract 0x8080 from the GB2312 code to be decoded, subtract 0x2121 (offset), that is, subtract 0xA1A1, and then point FileStream.Position to twice the result (two bytes a code) and read an Int16 to get the corresponding Unicode code. Below is a code I have in my Palm IP.

public class GB2312ToUnicode { private FileStream fs; private BinaryReader br; public GB2312ToUnicode(string index) { fs=new FileStream(index, FileMode.Open); br = new BinaryReader(fs); } public char Convert(byte[] b) { int index = ((b[0]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report