delphi

delphi中pos函数的用法是什么

小亿
515
2023-11-09 23:47:20
栏目: 编程语言

在Delphi中,Pos函数用于查找子字符串在给定字符串中的起始位置。其语法如下:

function Pos(const SubStr: string; const Str: string): Integer;

参数:

返回值:

示例用法:

var
  Str: string;
  SubStr: string;
  PosIndex: Integer;
begin
  Str := 'Hello, world!';
  SubStr := 'world';
  
  PosIndex := Pos(SubStr, Str);
  if PosIndex > 0 then
    ShowMessage('Found at position: ' + IntToStr(PosIndex))
  else
    ShowMessage('Not found.');
end;

在上述示例中,Pos(SubStr, Str)函数将返回子字符串"world"在字符串"Hello, world!"中的起始位置,即13。如果子字符串未找到,则返回0。

0
看了该问题的人还看了