본문 바로가기
Application/Delphi Lecture

String replace, getParam 함수

by 현이빈이 2008. 8. 13.
반응형

procedure replace(var source : string; find, repl : string);
var
  ind : integer;
begin
    ind := pos(find, source);
    if  ind > 0 then
    begin
         source := copy(source, 1, ind-1) + repl +
                   copy(source, ind + length(find), 10000);
         replace(source,  find, repl);
    end
end;

사용법은
 replace(str,'메롱','하이');
 ShowMessage(str);


function GetParam(str : string; index : integer) : string;
var
i, count : integer;
tmp : string;
param : array[1..1000] of string;
begin
str := str + #1;

for i := 1 to 1000  do param[i] := '';
i := 1;
count := 0;
while i <= length(str) do
begin
  if (str[i] = ',') or (str[i] = #1) then
  begin
    count := count + 1;
    param[count] := tmp;
    tmp := '';
  end else tmp := tmp + str[i];
         inc(i);
end;

result := param[index];
end;

사용법은
 str := '아쭈,왜이렇게,무식하다냐,-_-';
 ShowMessage(GetParam(str,3));

반응형