If there is a mail server string like smtp.gmail.com:587, how could I parse it to save "smtp.gmail.com" in a string variable and "587" in another?
function SplitAtChar(const Str: string; const Chr: char;
  out Part1, Part2: string): boolean;
var
  ChrPos: integer;
begin
  result := true;
  ChrPos := Pos(Chr, Str);
  if ChrPos = 0 then
    Exit(false);
  Part1 := Copy(Str, 1, ChrPos - 1);
  Part2 := Copy(Str, ChrPos + 1, MaxInt);
end;
Sample usage:
var
  p1, p2: string;
begin
  if SplitAtChar('smtp.gmail.com:587', ':', p1, p2) then
  begin
    ShowMessage(p1);
    ShowMessage(p2);
  end;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With