全角文字だけ抽出するには?

解決


おかっぴき  2005-07-07 00:56:45  No: 16237

strdataに'abcdタモリ0123いいとも'と半角全角混入した文字列が代入されてて
strdata2に'タモリいいとも'と全角文字だけ抽出したいのですが
以下の過去ログの「パスワードの入力チェック方法 」が一番近い
気がしたのでそれを参照しましたがうまくいきません。
エラーはinのとこで、この型には指定した演算子は使えません。と出ます。
DELPHI2005です。

const
    hank='abcdefghijklmnopqrstuvwxyz'+
         'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+
         '0123456789!#$%^&*+-.|';
var
   i:integer;
   strdata,strdata2:Ansistring;
   st,st2:TStringStream;
begin
      strdata:='abcdタモリ0123いいとも';  //元の文字列
      try
          st:=TStringStream.Create(strdata);
          st2:=TStringStream.Create('');
          for i:=1 to st.Size do begin
             if not (st.ReadString(i-1) in hank) then begin//エラー!
                st2.WriteString(st.ReadString(i-1));
             end;
          end;
          strdata2:=st2.DataString;      //タモリいいとも
      finally
          st.Free;
   st2.Free;
      end;
end;


anone  2005-07-07 01:57:59  No: 16238

処理速度はともかく、簡単にはこんな感じ

procedure TForm1.Button1Click(Sender: TObject);
var
  source, destination: string;
  i:integer;
begin
  source := 'abcdタモリ0123いいとも';
  destination := '';
  i := 0;
  repeat
    inc(i);
    if source[i] in LeadBytes then
    begin
      destination := destination+source[i]+source[i+1];
      inc(i);
    end;
  until i > Length(source);
  Label1.Caption := destination;
end;


おかっぴき  2005-07-07 03:21:15  No: 16239

anoneさん回答ありがとうございます。
LeadBytesなんて初めてみました。(~_~;)
サクっと解決です。
ありがとうございました!


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加