zoukankan      html  css  js  c++  java
  • 查看字符串在不同编码(ASCII、Unicode、UTF7、UTF8、Default、BigEndianUnicode)下的 Hex

    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Memo2: TMemo;
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        Button5: TButton;
        Button6: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure Button5Click(Sender: TObject);
        procedure Button6Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {从字符串到十六进制的函数}
    function StrToHex(str: string; AEncoding: TEncoding): string;
    var
      ss: TStringStream;
      i: Integer;
    begin
      Result := '';
      ss := TStringStream.Create(str, AEncoding);
      for i := 0 to ss.Size - 1 do
        Result := Result + Format('%.2x ', [ss.Bytes[i]]);
      ss.Free;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.ASCII);
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.Unicode);
    end;
    
    procedure TForm1.Button3Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF7);
    end;
    
    procedure TForm1.Button4Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF8);
    end;
    
    procedure TForm1.Button5Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.Default);
    end;
    
    procedure TForm1.Button6Click(Sender: TObject);
    begin
      Memo2.Text := StrToHex(Memo1.Text, TEncoding.BigEndianUnicode);
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Button1.Caption := 'To ASCII';
      Button2.Caption := 'To Unicode';
      Button3.Caption := 'To UTF7';
      Button4.Caption := 'To UTF8';
      Button5.Caption := 'To Default';
      Button6.Caption := 'To BigEndianUnicode';
    end;
    
    end.
    
    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 156
      ClientWidth = 353
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Memo1: TMemo
        Left = 0
        Top = 0
        Width = 145
        Height = 88
        Align = alLeft
        Lines.Strings = (
          'Memo1')
        ScrollBars = ssVertical
        TabOrder = 0
      end
      object Memo2: TMemo
        Left = 157
        Top = 0
        Width = 196
        Height = 88
        Align = alRight
        Lines.Strings = (
          'Memo2')
        ScrollBars = ssVertical
        TabOrder = 1
      end
      object Panel1: TPanel
        Left = 0
        Top = 88
        Width = 353
        Height = 68
        Align = alBottom
        TabOrder = 2
        object Button1: TButton
          Left = 16
          Top = 6
          Width = 73
          Height = 25
          Caption = 'Button1'
          TabOrder = 0
          OnClick = Button1Click
        end
        object Button2: TButton
          Left = 95
          Top = 6
          Width = 74
          Height = 25
          Caption = 'Button2'
          TabOrder = 1
          OnClick = Button2Click
        end
        object Button3: TButton
          Left = 175
          Top = 6
          Width = 82
          Height = 25
          Caption = 'Button3'
          TabOrder = 2
          OnClick = Button3Click
        end
        object Button4: TButton
          Left = 263
          Top = 6
          Width = 74
          Height = 25
          Caption = 'Button4'
          TabOrder = 3
          OnClick = Button4Click
        end
        object Button5: TButton
          Left = 16
          Top = 37
          Width = 96
          Height = 25
          Caption = 'Button5'
          TabOrder = 4
          OnClick = Button5Click
        end
        object Button6: TButton
          Left = 130
          Top = 37
          Width = 207
          Height = 25
          Caption = 'Button6'
          TabOrder = 5
          OnClick = Button6Click
        end
      end
    end
    
  • 相关阅读:
    updatepanel中不能使用fileupload的弥补方法
    AJAXPro用法,关于JS同步和异步调用后台代码的学习
    How do I get data from a data table in javascript?
    记不住ASP.NET页面生命周期的苦恼
    浅谈ASP.NET中render方法
    解决AjaxPro2中core.ashx 407缺少对象的问题
    ServU 6.0出来了
    关于X Server/Client和RDP的畅想
    这个Blog好像没有分页功能嘛
    AOC的显示器太烂了
  • 原文地址:https://www.cnblogs.com/del/p/1284923.html
Copyright © 2011-2022 走看看