C++中这样判断:
char *pos;
while(*pos!='\0')那DELPHI中怎么判断呢?谢谢!!
char *pos;
while(*pos!='\0')那DELPHI中怎么判断呢?谢谢!!
解决方案 »
- 指针问题请教。无法把指针地址赋值到全局变量是怎么回事?
- !!!!!高难度,至今没有找到答案: 多线程+ADO+SQL Server数据库运行时出错!!!!!!!!!!!
- delphi有没有友员函数啊,帮我看看这个问题怎么解决!!!
- 如何实现换行打印?
- 一个简单的问题,如何对字符串进行减操作?
- 怎么学好Delphi
- 好东西-各位小弟的网站,有时间请大家多多光顾(希望能方便得了大家!)
- 请帮助我的硬盘
- ADO 与 BDE 到底有什么异同? 谁好,好在那里?
- 如何对付使用结构化异常的调试问题
- 小问题,急,大伙帮帮忙
- !!!!!!!!!!!!!为什么我没办法使用copyfile函数呀!!!!!!!!!!!!!!
1是shortstring类型,如s:string[10],它的长度在string[0]中,没有结束符
2是string类型,它是以0结尾的,但字符也是从1开始(string[0]不可访问)
两种字串都可用length来测长度
C++:'\0'
DELPHI: #0;
i: integer;
s: string;
i := 1;
while(i <= Length(s)) do
begin Inc(i);
end;
假设字符串12345(长度载255以下)
c: 1 2 3 4 5 #0
DELPHI: 5 1 2 3 4 5
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;
与C的体系不一样的
所以Delphi的String处理能力,效率都要好不少
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.