[Delphi (Object Pascal)] Delphi 按照指定分隔符把字符串分割成两部分 →→→→→进入此内容的聊天室

来自 , 2020-08-25, 写在 Delphi (Object Pascal), 查看 178 次.
URL http://www.code666.cn/view/d82f9436
  1. function SplitStr(const S, Delim: string; out S1, S2: string): Boolean;
  2. var
  3.   DelimPos: Integer;  // position of delimiter in source string
  4. begin
  5.   // Find position of first occurence of delimiter in string
  6.   DelimPos := SysUtils.AnsiPos(Delim, S);
  7.   if DelimPos > 0 then
  8.   begin
  9.     // Delimiter found: split and return True
  10.     S1 := Copy(S, 1, DelimPos - 1);
  11.     S2 := Copy(S, DelimPos + Length(Delim), MaxInt);
  12.     Result := True;
  13.   end
  14.   else
  15.   begin
  16.     // Delimiter not found: return false and set S1 to whole string
  17.     S1 := S;
  18.     S2 := '';
  19.     Result := False;
  20.   end;
  21. end;
  22. //delphi/2326

回复 "Delphi 按照指定分隔符把字符串分割成两部分"

这儿你可以回复上面这条便签

captcha