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;
処理速度はともかく、簡単にはこんな感じ
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;
anoneさん回答ありがとうございます。
LeadBytesなんて初めてみました。(~_~;)
サクっと解決です。
ありがとうございました!
ツイート | ![]() |