C++中这样判断:  
 char *pos;
  
  while(*pos!='\0')那DELPHI中怎么判断呢?谢谢!!

解决方案 »

  1.   

    delphi的string有两种:
    1是shortstring类型,如s:string[10],它的长度在string[0]中,没有结束符
    2是string类型,它是以0结尾的,但字符也是从1开始(string[0]不可访问)
    两种字串都可用length来测长度
      

  2.   

    如果你是想问NULL在DELPHI中对应的码值的话,就是这样的:
      C++:'\0'
      DELPHI: #0;
      

  3.   

    〉〉不用长度。必须判断一下有无结束符。既然用D就不能用C的思想
    i: integer;
    s: string;
      
      i := 1;
      while(i <= Length(s)) do
    begin  Inc(i);
    end;
      

  4.   


    假设字符串12345(长度载255以下)
    c:      1 2 3 4 5 #0
    DELPHI: 5 1 2 3 4 5
      

  5.   

    类似C的用法:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      s: string;
      i: integer;
    begin
      s := '12345';
      i := 1;
      while s[i] <> #0 do
      begin
        showmessage(s[i]);
        inc(i);
      end;
    end;
      

  6.   

    Delphi的String没有结束符的
    与C的体系不一样的
    所以Delphi的String处理能力,效率都要好不少
      

  7.   

    帮助里的.前几天被#0困扰过.. 2006的帮助
    ms-help://borland.bds4/bds4ref/html/StringTypes.htm#AboutStrings
    Working with null-Terminated Strings 
    Many programming languages, including C and C++, lack a dedicated string data type. These languages, and environments that are built with them, rely on null-terminated strings. A null-terminated string is a zero-based array of characters that ends with NUL (#0); since the array has no length indicator, the first NUL character s the end of the string. You can use Delphi constructions and special routines in the SysUtils unit (see Standard routines and I/O ) to handle null-terminated strings when you need to share data with systems that use them.
     
    For example, the following type declarations could be used to store null-terminated strings.
     type
      TIdentifier = array[0..15] of Char;
      TFileName = array[0..259] of Char;
      TMemoText = array[0..1023] of WideChar;
    With extended syntax enabled ({$X+}), you can assign a string constant to a statically allocated zero-based character array. (Dynamic arrays won't work for this purpose.) If you initialize an array constant with a string that is shorter than the declared length of the array, the remaining characters are set to #0.