메뉴 건너뛰기

AcroSoft

델파이 질문 및 답변

AcroEdit 에선 아래 코드처럼 구현합니다...




function TAssEditor.DoSpacesToTab(const Str: string): string;
var
nIndex, nLen, nTmpLen, nNeedSpaceCount : integer;
TmpStr : string;
begin
Result := '';
nLen := Length(Str);
nIndex := 1;
while nIndex <= nLen do
begin
if Str[nIndex] = CHAR_SPACE then
begin
nNeedSpaceCount := FTabSize - (Length(ExpandStr(Result)) mod FTabSize);
TmpStr := GetStringWhile(Str, [CHAR_SPACE], nIndex);
nTmpLen := Length(TmpStr);
if nTmpLen = 0 then
Result := Result + Str[nIndex]
else if nTmpLen = nNeedSpaceCount then
Result := Result + CHAR_TAB
else if nTmpLen > nNeedSpaceCount then
begin
Result := Result + CHAR_TAB;
Delete(TmpStr, 1, nNeedSpaceCount);
Dec(nIndex, Length(TmpStr));
end
else
Result := Result + TmpStr;
end
else
begin
Result := Result + Str[nIndex];
Inc(nIndex);
end;
end;
end;




위로