delphi2007
1、有3种类型的字符串
ShortString:255个字符
AnsiString:表示8位的ansi,DBCS ANSI,MBCS ANSI等。也称为长字符串。
WideString:表示Unicode;可用于多用户服务、多种语言应用程序。
这三种字符串可以在赋值和表达式等各种操作中混用,也就是说编译器会自动进行这三种之间的类型转换。
Win32平台系统默认为AnsiString。
2、AnsiString
该类型的变量是一个4字节指针,指向包含字符串内容的在堆上动态分配的内存块。该内存块的前8个字节中,前2个字节记录字符串长度,后2个字节记录引用数量。生存期自管理。
copy-on-write:当且仅当字符串的引用计数大于1时,如果字符串中任意字符发生变化,那么就产生一个新的字符的副本。
Char、PChar,AnsiChar,PAnsiChar,AnsiString这几个类型实现对单字节或多字节字符的支持。
注意:通过S[i]这种方式来访问第i个字符是不靠谱的,应使用相应的方法,大多以Ansi开头的。
3、WideString
表示unicode格式的字符串。WideChar,PWideChar,WideString。
WideString不是引用计数的,但生命周期是自管理的!
4、null结尾的字符串
用指针方式声明的字符串,都以null(#0)为结束字符。可以通过强转为string,实现字符串常见操作,如2个字符串的连接等。
5、Null-terminated string functions
Function
|
Description
|
StrAlloc
|
Allocates a character buffer of a given size on the heap.
|
StrBufSize
|
Returns the size of a character buffer allocated using StrAlloc or StrNew.
|
StrCat
|
Concatenates two strings.
|
StrComp
|
Compares two strings.
|
StrCopy
|
Copies a string.
|
StrDispose
|
Disposes a character buffer allocated using StrAlloc or StrNew.
|
StrECopy
|
Copies a string and returns a pointer to the end of the string.
|
StrEnd
|
Returns a pointer to the end of a string.
|
StrFmt
|
Formats one or more values into a string.
|
StrIComp
|
Compares two strings without case sensitivity.
|
StrLCat
|
Concatenates two strings with a given maximum length of the resulting string.
|
StrLComp
|
Compares two strings for a given maximum length.
|
StrLCopy
|
Copies a string up to a given maximum length.
|
StrLen
|
Returns the length of a string.
|
StrLFmt
|
Formats one or more values into a string with a given maximum length.
|
StrLIComp
|
Compares two strings for a given maximum length without case sensitivity.
|
StrLower
|
Converts a string to lowercase.
|
StrMove
|
Moves a block of characters from one string to another.
|
StrNew
|
Allocates a string on the heap.
|
StrPCopy
|
Copies a Pascal string to a null-terminated string.
|
StrPLCopy
|
Copies a Pascal string to a null-terminated string with a given maximum length.
|
StrPos
|
Returns a pointer to the first occurrence of a given substring within a string.
|
StrRScan
|
Returns a pointer to the last occurrence of a given character within a string.
|
StrScan
|
Returns a pointer to the first occurrence of a given character within a string.
|
StrUpper
|
Converts a string to uppercase.
|
这些标准函数都可以处理多字节格式的字符串,同Ansi-函数。