5,392
社区成员
发帖
与我相关
我的任务
分享
function FindStr(ShortStr: string; LongStrIng: string): Integer;
//在一个字符串中找某个字符的位置
var
locality: integer;
begin
locality := Pos(ShortStr, LongStrIng);
if locality = 0 then
Result := 0
else
Result := locality;
end;
//取得某个字符后所有字符
function getends(s, s1: string): string;
var
i1, i2: integer;
begin
i1 := FindStr(s1, s) + length(s1);
i2 := length(s);
result := copy(s, i1, i2 - i1 + 1);
end;
function copyab(s, s1: string; s2: string): string;
var
i1, i2: integer;
begin
i1 := pos(s1, s);
i2 := pos(s2, s);
result := copy(s, i1 + length(s1), i2 - i1 - length(s1));
end;
function formattext(s: string): string;
begin
s := trim(s);
s := stringreplace(s, #13, '', [rfreplaceall]);
s := stringreplace(s, #13#10, '', [rfreplaceall]);
s := stringreplace(s, #10#13, '', [rfreplaceall]);
s := stringreplace(s, #10, '', [rfreplaceall]);
s := stringreplace(s, ' ', '|', [rfreplaceall]);
s := stringreplace(s, ' ', '', [rfreplaceall]);
s := stringreplace(s, ' ', '', [rfreplaceall]);
s := stringreplace(s, ' ', '', [rfreplaceall]);
result := s;
end;
procedure SeparateTerms(s: string; Separator: char; Terms: TStringList);
//分割字符串过程
var
hs: string;
p: integer;
begin
Terms.Clear; // 清除字符串中的内容
if Length(s) = 0 then // 长度为0
Exit;
p := Pos(Separator, s);
while P <> 0 do
begin
hs := Copy(s, 1, p - 1); // 复制字符
Terms.Add(hs); // 添加到列表
Delete(s, 1, p); // 删除字符和分割符
p := Pos(Separator, s); // 查找分割符
end;
if Length(s) > 0 then
Terms.Add(s); // 添加剩下的条目
end;
function delm(s: string): string;
begin
if pos(':', s) = 1 then
result := stringreplace(s, ':', '', [rfreplaceall])
else
result := s;
end;
//格式化后不保留回车
function ReplaceSub(str, sub1, sub2: string): string;
var
aPos: Integer;
rslt: string;
begin
aPos := Pos(sub1, str);
//取得子字符串的位置
rslt := '';
while (aPos <> 0) do
begin
rslt := rslt + Copy(str, 1, aPos - 1) + sub2;
Delete(str, 1, aPos + Length(sub1));
//删除要替换的字符串
aPos := Pos(sub1, str);
end;
Result := rslt + str;
//添加要字符串
end;