<Delphi版>
原文:http://delphi.ktop.com.tw/board.php?cid=30&fid=69&tid=86372
其他相關:
LCMapString函式MSDN
http://msdn.microsoft.com/en-us/library/dd318700(v=vs.85).aspx
LCMapStringEx函式MSDN
http://msdn.microsoft.com/en-us/library/dd318702(v=vs.85).aspx
如何分辨中英文夾雜的字串中的中英文
http://delphi.ktop.com.tw/board.php?cid=30&fid=1498&tid=91302
控制輸入為全形字
http://delphi.ktop.com.tw/board.php?cid=168&fid=923&tid=44666
繁簡體字轉換:
http://www.99inf.net/SoftwareDev/Delphi/35515.htm
半形-->全形
procedure TForm1.Button1Click(Sender: TObject);
var
Chr : array [0..255] of char;
begin
Windows.LCMapString(
GetUserDefaultLCID(),
LCMAP_FULLWIDTH,
PChar(Edit1.Text),
Length(Edit1.Text) + 1,
Chr,
Sizeof(chr)
);
Edit2.Text := chr;
end;
全形-->半形
procedure TForm1.Button3Click(Sender: TObject);
var
Chr : array [0..255] of char;
begin
Windows.LCMapString(
GetUserDefaultLCID(),
LCMAP_HALFWIDTH,
PChar(Edit2.Text),
Length(Edit2.Text) + 1,
chr,
Sizeof(chr)
);
Edit1.Text := Chr;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Chr : array [0..255] of char;
begin
Windows.LCMapString(
GetUserDefaultLCID(),
LCMAP_FULLWIDTH,
PChar(Edit1.Text),
Length(Edit1.Text) + 1,
Chr,
Sizeof(chr)
);
Edit2.Text := chr;
end;
全形-->半形
procedure TForm1.Button3Click(Sender: TObject);
var
Chr : array [0..255] of char;
begin
Windows.LCMapString(
GetUserDefaultLCID(),
LCMAP_HALFWIDTH,
PChar(Edit2.Text),
Length(Edit2.Text) + 1,
chr,
Sizeof(chr)
);
Edit1.Text := Chr;
end;
Flag | Meaning |
LCMAP_BYTEREV | Use byte reversal. For example, if the application passes in 0x3450 0x4822, the result is 0x5034 0x2248. |
LCMAP_FULLWIDTH | Use Unicode (wide) characters where applicable. This flag and LCMAP_HALFWIDTH are mutually exclusive. 使用Unicode(寬)字元如適用。… |
LCMAP_HALFWIDTH | Use narrow characters where applicable. This flag and LCMAP_FULLWIDTH are mutually exclusive. 在適用情況下使用窄字元。… |
LCMAP_HIRAGANA | Map all katakana characters to hiragana. This flag and LCMAP_KATAKANA are mutually exclusive. |
LCMAP_KATAKANA | Map all hiragana characters to katakana. This flag and LCMAP_HIRAGANA are mutually exclusive. |
LCMAP_LINGUISTIC_CASING | Use linguistic rules for casing, instead of file system rules (default). This flag is valid with LCMAP_LOWERCASE or LCMAP_UPPERCASE only. |
LCMAP_LOWERCASE | For locales and scripts capable of handling uppercase and lowercase, map all characters to lowercase. |
LCMAP_SIMPLIFIED_CHINESE | Map traditional Chinese characters to simplified Chinese characters. This flag and LCMAP_TRADITIONAL_CHINESE are mutually exclusive. |
LCMAP_SORTKEY | Produce a normalized sort key. If the LCMAP_SORTKEY flag is not specified, the function performs string mapping. For details of sort key generation and string mapping, see the Remarks section. |
LCMAP_TITLECASE | Windows 7: Map all characters to title case, in which the first letter of each major word is capitalized. |
LCMAP_TRADITIONAL_CHINESE | Map simplified Chinese characters to traditional Chinese characters. This flag and LCMAP_SIMPLIFIED_CHINESE are mutually exclusive. |
LCMAP_UPPERCASE | For locales and scripts capable of handling uppercase and lowercase, map all characters to uppercase. |
<C++Builder版>
原文:http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=80118
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int iLong = Memo1->Lines->Text.Length();
unsigned char *x = new unsigned char[iLong];
unsigned char *hz = new unsigned char[iLong*2];
x = Memo1->Lines->GetText();
int index=0;
for (int i=0; i<=iLong; i++) {
if (x[i] <= 0x80) {
if (x[i] > ' ' && x[i] < '~') {
hz[index] = 163;
hz[index+1] = 128+x[i];
index += 2;
} else if (x[i] == ' ') {
hz[index] = 161;
hz[index+1] = 161;
index += 2;
} else {
hz[index] = x[i];
index++;
}
} else {
hz[index] = x[i];
hz[index+1] = x[i+1];
index += 2;
i++;
}
}
Memo2->Lines->SetText(hz);
delete [] x;
delete [] hz;
}
{
int iLong = Memo1->Lines->Text.Length();
unsigned char *x = new unsigned char[iLong];
unsigned char *hz = new unsigned char[iLong*2];
x = Memo1->Lines->GetText();
int index=0;
for (int i=0; i<=iLong; i++) {
if (x[i] <= 0x80) {
if (x[i] > ' ' && x[i] < '~') {
hz[index] = 163;
hz[index+1] = 128+x[i];
index += 2;
} else if (x[i] == ' ') {
hz[index] = 161;
hz[index+1] = 161;
index += 2;
} else {
hz[index] = x[i];
index++;
}
} else {
hz[index] = x[i];
hz[index+1] = x[i+1];
index += 2;
i++;
}
}
Memo2->Lines->SetText(hz);
delete [] x;
delete [] hz;
}
沒有留言:
張貼留言