// /在分隔符字符串Delim第一次出现时分割字符串S。
// / S1设置为Delim之前的S的子串,S2设置为Delim的其余部分
// / S 在 Delim 之后。如果 S 包含 Delim 则返回 True,否则返回 False。
// / 如果没有找到 Delim,则 S1 设置为 S,S2 设置为空
// / 字符串。
function SplitStr(const S, Delim: string; out S1, S2: string): Boolean;
var
DelimPos: Integer; // position of delimiter in source string
begin
// Find position of first occurence of delimiter in string
DelimPos := AnsiPos(Delim, S);
if DelimPos > 0 then
begin
// Delimiter found: split and return True
S1 := Copy(S, 1, DelimPos - 1);
S2 := Copy(S, DelimPos + Length(Delim), MaxInt);
Result := True;
end
else
begin
// Delimiter not found: return false and set S1 to whole string
S1 := S;
S2 := '';
Result := False;
end;
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.068849086761475 seconds