Delphi character and string [1]-string, ansistring, widestring, string [N], character string

Source: Internet
Author: User
// The most common stringvar STR: string; {definition} begin STR: = ''; {value assignment} showmessage (inttostr (length (STR); {length is: 4} end;
  
   
 // Long string ansistring; by default in the current version (2007), string is ansistringvar STR: ansistring; begin STR: = 'case '; showmessage (inttostr (length (STR); {length: 4} end;
  
   
 // Wide string widestring (less efficient than ansistring) var STR: widestring; begin STR: = 'case'; showmessage (inttostr (length (STR); {the length is: 2} end;
  
   
 // Fixed-length string var str1: String [6]; {the specified size cannot exceed 255} str2: String [100]; begin {memory occupied when the value is less} str1: = 'case'; showmessage (str1); {In case} showmessage (inttostr (length (str1); {4; this is the string length} showmessage (inttostr (sizeof (str1); {7; this is the memory size} {if it is given more, it will be truncated} str1: = 'in case of Delphi blog'; showmessage (str1); {In case} showmessage (inttostr (length (str1); {6; this is the actually saved string length} showmessage (inttostr (sizeof (str1); {7; this is the memory size} {question: isn't the declared size 6? Why is sizeof 7? } {Because a fixed-length string will have an extra first byte to remember the actual length of the string} {for example, if str2 is assigned the following value, then its first byte (str2 [0]) the character 'a'} str2: = 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'; {65} showmessage (str2 [0]); {A} showmessage (inttostr (ord (str2 [0]); {65; this is the sequence number of 'A' in the ASCII sequence, is it used} {then can we use ord (str2 [0]) instead of length to determine the length of the string? } {You can set a fixed-length string. Not only can you read the string, but you can also set it like setlength} end;
  
   
 // Response string; it is equivalent to string [255] var STR: Response string; begin STR: = 'in case of Delphi blog'; showmessage (STR ); {In case of Delphi blog} showmessage (inttostr (sizeof (STR); {256; this is the size} showmessage (inttostr (length (STR); {18; this is the actual length} showmessage (inttostr (ord (STR [0]); {18; this is the length retrieved from the first byte} end;
  
   
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.