strlen,length
pos,strpos
这几个两对函数有何区别,是否本来就一样?

解决方案 »

  1.   

    看帮助参数的类型不同,strlen,strpos的参数类型是pchar其他两个是string
      

  2.   

    StrLen returns the number of characters in Str, not counting the null terminator.
    返回的是真正的字符的长度,不包含结束位之后的。
    Length returns the number of characters actually used in the string or the number of elements in the array.返回实际字符创或者数组的长度
    它们的区别可以看我给的这个例子
    //////////////////////////////////////////
    procedure TForm1.Button1Click(Sender: TObject);
    var str1:string;
        arr1:array[1..10] of Char;
    begin
        fillChar(arr1,length(arr1),0);//把数组初始化为全零
        //零在字符串中被当成结束位
        str1:=arr1;
        showmessage('用strlen得到的长度'+IntToStr(strlen(PChar(str1))));
        showmessage('用length得到的长度'+IntToStr(length(str1)));
    end;
      

  3.   

    StrPos returns a pointer to the first occurrence of Str2 in Str1. If Str2 does not occur in Str1, StrPos returns nil (Delphi) or NULL (C++).
    ////////////////////////
    n Delphi, Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.