お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"全角対応 StrToIntDef"

この発言に対し以下のコメントが寄せられています
#01224 十兵衛 さん RE:全角対応 StrToIntDef

こんにちは、武丸タケシです。 全角対応の StrToIntDef です。 2001 なんていう混在の仕方にも対応しています。 おかしなところがあればご指摘ください。m(__)m uses Math function ZenToIntDef(const S: String; Default: Integer): integer; const SUJI = '0123456789'; var W : WideString; Code,i,iy : integer; begin W := S; for i:=1 to Length(W) do //TrimLeft begin if (W[i] <> ' ')and(W[i] <> ' ') then begin W := Copy(W,i,Length(W)-i+1); break; end; end; for i:=Length(W) downto 1 do //TrimRight begin if (W[i] <> ' ')and(W[i] <> ' ') then begin W := Copy(W,1,i); break; end; end; Val( W,result,Code ); if Code > 0 then begin result := 0; for i:=1 to Length(W) do begin iy := AnsiPos( W[i], SUJI ); if iy = 0 then begin Val( W[i],iy,Code ); if Code > 0 then begin result := Default; exit; end; end else iy := iy div 2; if iy > 0 then result := result + Trunc(iy * Power(10, Length(W)-i)); end; end; end; 武丸タケシ(SNC19296)  - FDELPHI MES(16):玉石混淆みんなで作るSample蔵【見本蓄積】 01/01/04 - Original document by 武丸タケシ 氏 ID:(SNC19296)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum