(Copyright requirements: this article only authorizes 9CBS to use, separate ccrun reproduced, other personal and websites must not be reproduced, extract, if there is special demand to contact the author)
16. Some specific usage of C / C languages in CB
2) Is ANSISTRING that came from Delphi?
A: The core component VCL of the CB is written in the Object Pascal language, so the properties of the VCL components of the CB are all use long string, such as: text, name, caption, etc., use Object Pascal long string. Based on this relationship, CB has to establish the corresponding category of the Object Pascal's long String, which we call it as ASISTRING.
3) What is the difference between ANSISTRING and STRING?
A: C Builder has such a definition in sysdefs.h header:
Typedef ansistring string;
From this point of view, it is exactly the same, but it is more convenient to write, and the former is more intent.
4) Can I introduce some common functions of the ANSISTRING class and their usage?
A: Of course, you can do a brief introduction to the common function:
Member function syntax function c_str char * _fastcall c_str () const returns a pointer to Delete void _fastcall Delete string data (int index, int count) from the index at the beginning of count characters removed Insert void _fastcall Insert (const AnsiString & str, int index) by the InDex starts to insert characters STR to the original string iSempty Bool _fastcall iSempty () const Back to string is empty, True Represents empty string length INT _FASTCALL length () Const Return Strings Length LowerCase Ansistring _fastCall LowerCase () Const will character Cardship letters in strings into lowercase UPPERCASE ANSISTRING _FASTCALL UPPERCASE () Const Cover the lowercase letters in the string into larger written pos int _fastcall pos (cont Anstring & substr) const; find out the sub-string in the original string by the first few locations start SubString AnsiString _fastcall SubString (int index, int count) const returns the index of the count characters take back ToDouble double _fastcall ToDouble () const double switch character accuracy values ToInt int _fastcall ToInt () const characters transformed into plastic IntToStr Ansistring _fastcall INTOSTR (INT VALUE) Returns a new string of shaping _fastcall trim () conststring _fastcall trim (), will return the original string before and after the blank or control character is then returned to widechar wchar_t fastcall widechar (Wchart * Dest , int dependsize) Const conversion ANSISTRING to a wide character array (common in COM)
5) What is the difference between the ANSTSTRING member function and the traditional string function?
A: We can view the difference between them through a comparison table:
Ansistring member function function Traditional string function = string copy strcpy = string merge strcat string connection is not ==,! =, <=,>,> = String comparison strcmp c_STR () mutual conversion However, you can use the pointer to implement the delete delete sub-string without insert insert. No longer string length strlen lowercase letters to lowercase strlwr POS to find a string strstr setLength Set string length without TOINT Turning Being a Double Precision Sprintf Uppercase Letter Conversion Strupr6) How to implement the traditional string and the mutual conversion of the ANSISTRING string?
A: Traditional C language is to form a string using characters (the end of the string must have '/ 0' as the end flag), and its format and Ansistring are not the same. Since I use the ANSISTRING format in CB, sometimes it is also inevitable to be converted, we can achieve the following three methods:
Method 1: ANSISTRING string converted into a string array:
First use the c_str () method in the Ansistring category into the traditional string array, then copy it to the character array with STRCPY:
Char S1 [20];
STRCPY (S1, EDIT1-> text.c_str ());
Method 2: Ansistring Convert to traditional strings to use character pointers to achieve:
Can be implemented by character pointers:
Char * S;
s = edit-> text.c_str ();
Method 3: Implementing a traditional string with a character pointer to ANSISTRING:
Char * s = "Try a try, see if you can succeed!"
Edit-> text = s;
(Endlessly)