面 试2?jijie
delphi:
//---------------------------------------------------------------------------
function CharToWord(CharHi, CharLo: Char): Word;
begin
Result := (Ord(CharHi) shl 8) + Ord(CharLo);
end;
-----------------
zai c# ruhe shixian
thanks!!!!!
问题点数:0、回复次数:9Top
1 楼fancyf(凡瑞)回复于 2005-06-04 17:40:00 得分 0
public short CharToInt(byte CharHi, byte CharLo)
{
return (short)((CharHi<<8) + CharLo);
}Top
2 楼sh_caizicheng(每天一小步,成就一大步)回复于 2005-06-04 17:49:37 得分 0
shang mian de han shu yinggai jia zai na er hao ya? thanks!!
//---------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace caizi
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(80, 64);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(304, 19);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(256, 136);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(80, 208);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(312, 19);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(600, 405);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
textBox2.Text=textBox1.Text;
}
}
}
Top
3 楼fancyf(凡瑞)回复于 2005-06-04 17:55:08 得分 0
你应该说清楚你的目的,因为.net中一个字符占16位,一个word存不下的,上面的函数是对byte进行操作,你要是对char进行操作的话所有数据类型长度都要加倍Top
4 楼sh_caizicheng(每天一小步,成就一大步)回复于 2005-06-04 18:07:42 得分 0
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
KI = #$1B + '$B'; {漢字IN : このコードに続く文字コードは漢字コードとする}
KO = #$1B + '(B'; {漢字OUT : このコードに続く文字コードはANKコードとする }
//---------------------------------------------------------------------------
function WordToChar(N: Word): String;
begin
Result := Char(Hi(N)) + char(Lo(N));
end;
//---------------------------------------------------------------------------
function CharToWord(CharHi, CharLo: Char): Word;
begin
Result := (Ord(CharHi) shl 8) + Ord(CharLo);
end;
//public short CharToInt(byte CharHi, byte CharLo)
//{
// return (short)((CharHi<<8) + CharLo);
//}
//------------------------------------------------------
function SjisToJis(sjis: Word): Word; assembler;
asm
shl ah, 1
sub al, 1fh
js @1
cmp al, 61h
adc al, 0deh
@1:
add ax, 1fa1h
and ax, 7f7fh
end;
//-------------------------------------------------------
function StrSjisToJis(str: string): string;
var
idx: integer;
flag_ANK: boolean;
begin
{初期値設定}
Result := '';
flag_ANK := True;
idx := 0;
while (idx < Length(str)) do //while string input
//==================================================================================
begin
Inc(idx); // adjust+1
if ByteType(str, idx) = mbLeadByte then
//判断字符串的第一个字符是否是字
begin// 是字
{ANKから2バイトコードへ移行する場合、KIを設定する}
if flag_ANK then
begin
flag_ANK := False;
Result := Result + KI;
end;
{SJIS to JIS変換する}
Result := Result + WordToChar(SjisToJis(CharToWord(str[idx],str[idx + 1])));
Inc(idx);
end
else
begin
{2バイトコードからANKへ移行する場合、KOを設定する}
if not flag_ANK then
begin
flag_ANK := True;
Result := Result + KO;
end;
{ASCIIコードと同一なのでコード変換しない}
Result := Result + str[idx];
end; {if-else}
//==================================================================================
end; {while}
{改行時にANKに戻す}
if not flag_ANK then
begin
Result := Result + KO;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text := StrSjisToJis(edit1.Text);
end;
end.Top
5 楼sh_caizicheng(每天一小步,成就一大步)回复于 2005-06-04 18:08:31 得分 0
qing kan !!!
ru he zai c# zhong
shi xian!! xiexie!!1Top
6 楼fancyf(凡瑞)回复于 2005-06-04 18:11:44 得分 0
晕,我不懂delphiTop
7 楼sh_caizicheng(每天一小步,成就一大步)回复于 2005-06-04 18:13:32 得分 0
function WordToChar(N: Word): String;
begin
Result := Char(Hi(N)) + char(Lo(N));
end;
na zhe ge ru he bianTop
8 楼sh_caizicheng(每天一小步,成就一大步)回复于 2005-06-04 18:20:32 得分 0
ji!
up!
Top
9 楼dutguoyi(新鲜鱼排)回复于 2005-06-04 19:20:41 得分 0
upTop




