¾È³çÇϼ¼¿ä. Ÿ¶ôõ»ç ÀÔ´Ï´Ù. µ¨ÆÄÀÌ ÀÔ¹®¼°¡ ¾ø´Ù°í Çؼ ¾²°í Àִµ¥, ¾µ°Ô ¾ø¾î¼ Á¦°¡ °³¹ßÇÑ ¶óÀ̺귯 Áß¿¡ ÀÖ´Â ¹®ÀÚ¿ ÆÄ½Ì ÇÔ¼ö ¿Ã¸³´Ï´Ù.
Delphi7, DelphiXE6, DelphiXE7, ¸ð¹ÙÀÏ ¿¡¼ Å×½ºÆ® µÇ¾ú½À´Ï´Ù.
xyToken ÀÌ ÆÄ½Ì ÇÔ¼ö ÀÌ°í,
xySplit, xySplitName, xySplitValueÀº AText ¹®ÀÚ¿À» ASub ±âÁØÀ¸·Î µÑ·Î ÂÉ°³´Â ÇÔ¼ö ÀÔ´Ï´Ù.
(example 1)
var i, nCnt: integer; MyList: TszString; sTest: string; begin sTest := 'One'#1'Two'#1'Three'#1'Four'; nCnt := xyToken(MyList, AText, #1);
for i := 0 to nCnt - 1 do ShowMessage(MyList[i]) ....
(example 2) var MyList: TStringList; sTest: string; begin sTest := 'One'#1'Two'#1'Three'#1'Four'; MyList := TStringList.Create; MyList.Text := xyToken(AText, #1, #13#10);
(source)
type TszString = array of string;
function xyToken(var AList: TszString; const AText: string; const ASub: string): integer; var i, nPast, nPos, nLen, nSub: integer; begin integer(Result) := 0; nLen := Length(AText); nSub := Length(ASub);
nPos := Pos(ASub, AText); nPast := 1; while nPos > 0 do begin if Result = Length(AList) then SetLength(AList, Result + 10);
if nPos = nPast then AList[Result] := '' else AList[Result] := Copy(AText, nPast, nPos - nPast); Result := Result + 1;
nPast := nPos + nSub; nPos := PosEx(ASub, AText, nPast); end;
if nPast <= nLen then begin if Result = Length(AList) then SetLength(AList, Result + 1); AList[Result] := Copy(AText, nPast, MaxInt); Result := Result + 1; end; end;
function xyToken(const AText: string; const ASub: string = #13#10; const ADelim: string = #13#10): string; var i, nPast, nPos: integer; begin Result := ''; nPos := Pos(ASub, AText); while nPos > 0 do begin if nPos = nPast then Result := Result + ADelim else Result := Result + Copy(AText, nPast, nPos - nPast) + ADelim; nPast := nPos + 1; nPos := PosEx(ASub, AText, nPast); end;
if nPast <= Length(AText) then Result := Result + Copy(AText, nPast, MaxInt) + ADelim; end;
function xySplit(var AName, AValue: string; const AText, ASub: string): integer; begin Result := Pos(ASub, AText); if Result < 1 then begin AName := AText; AValue := ''; end else begin AName := Copy(AText, 1, Result - 1); AValue := Copy(AText, Result + Length(ASub), MaxInt); end; end;
function xySplitName(const AText, ASub: string): string; var nPos: integer; begin nPos := Pos(ASub, AText); if nPos < 2 then Result :
|