User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Programación en C++ Builder

 Arrays (arrays)
 Pointers
3. Example of class in c + +
8. AnsiString class methods
 C + + projects
 Packages, distribute an application without installation
 Exchange or bubble sorting
 String string.h functions

8. AnsiString class methods

AnsiString class methods

AnsiCompare
This method compares two strings AnsiString with case-sensitive (case-sensitively).

 int __fastcall AnsiCompare (const AnsiString & rhs) const; 

If the two strings are equal, returns 0.
If the chain that requires the comparison is less than the last as an argument, the return value is negative. Otherwise, is greater than 0.

Condition Return Value
S1> S2 > 0
S1 <S2 <0
S1 = S2 = 0

Example:

 AnsiString str = "Elephant";
ShowMessage (Cadena.AnsiCompare ("Elephant")); / / Response 0
ShowMessage (Cadena.AnsiCompare (Elefantf ")) / / -1 Reply
ShowMessage (Cadena.AnsiCompare (Elefantd ")) / / Answer 1 

AnsiCompareIC
Compares the string with another specified string AnsiString not case sensitive (case insensitively).

 int __fastcall AnsiCompareIC (const AnsiString and d.) const; 

Compares this AnsiString to rhs, with case sensitivity. The compare operation is controlled by the current Windows locale and is Not Necessarily the Same as the AnsiString using comparison operators. AnsiCompare is based on a locale-specific collating order. The return value is Shown Below:

Condition Return Value
S1> S2 > 0
S1 <S2 <0
S1 = S2 = 0

AnsiLastChar
Ansip
AnsiString
ByteType
c_str
Gives a pointer to char string data.

 char * __fastcall c_str () const; 

CurrToStr
CurrToStrF
Delete
Deletes a part of the chain.

 void __fastcall Delete (int index, int count); 

Removes count characters from the string beginning with the character at index.

FloatToStrF
FmtLoadStr
Format
FormatFloat
Insert
Add text to a string in the position indicated.

 void __fastcall Insert (const AnsiString & str, int index); 

Inserts the string str Into this AnsiString Beginning at the position of index.

IntToHex
Converts a number into a string of hexadecimal (base 16).

 static AnsiString __fastcall IntToHex (int value, int digits); 

Value is the number to convert. Digits Indicates the minimum number of hexadecimal digits.

IsDelimiter
IsEmpty
See if a string is empty.

 bool __fastcall IsEmpty () const; 

AnsiString Returns true if this is empty, false Otherwise.

IsLeadByte
IsPathDelimiter
IsTrailByte
LastDelimiter

Length
Give the length of a string in characters.

 int __fastcall Length () const; 

LoadStr
LowerCase
Convert string to lowercase.

 LowerCase __fastcall AnsiString () const; 

operator! = operator [] operator + operator + = operator <operator <=
operator = operator == operator> operator> =

Pos
Give the position of a substring within a string.

 int __fastcall Pos (const AnsiString & substr) const; 

Returns the index in the AnsiString at Which the substr substring begins. If the substring is Not Contained in the AnsiString, Pos returns 0.

SetLength

Part a string according to the specified length.

 __fastcall void SetLength (int newLength) 

Truncates the length of the string is less Than newLength if the current string length. SetLength Does Not Increase the length of the string.

StringOfChar

It delivers a string from a character, repeated n times.

 static AnsiString __fastcall StringOfChar (char ch, int count); 

Returns a string containing characters with the character count value Given by ch. For example,
AnsiString s = AnsiString:: StringOfChar ('A', 10);
sets s to the string 'AAAAAAAAAA'.

SubString
Returns a substring from a string beginning at the position indicated and according to the specified length.

 SubString __fastcall AnsiString (int index, int count) const; 

Returns a new AnsiString That is a substring of this AnsiString. The substring contains characters Beginning at index count.

ToDouble

Converts a string to a real number double. If you can not make an exception occurs.

 double __fastcall ToDouble () const; 

Converts the string to a floating-point value. The string must-Consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional 'E' or 'e' Followed by a signed integer. Leading and trailing blanks in the string Are ignored. The global DecimalSeparator variable defines the character That Must Be Used as a decimal point. Thousand separators and currency symbols Are not allowed in the string. If the string Does not Contain a valid value, an exception is Thrown EConvertError.

ToInt

Converts a string to an integer. If you can not make an exception occurs.

 int __fastcall ToInt () const; 

Given Converts the string to an integer value and returns the integer. If the string Does not Contain a valid value, an exception is Thrown EConvertError.

ToIntDef
Converts a string to an integer. If you can not convert is given a default and there is no exception.

 int __fastcall ToIntDef (int defaultValue) const; 

Given Converts the string to an integer value and returns the integer. If the string Does not Contain a valid value, the value Given by defaultValue is returned.

Trim
Removes blanks or control characters before and after the string.

 Trim __fastcall AnsiString () const; 

Trim returns to new AnsiString Removing Leading and trailing spaces and control characters. Use Trim to remove blank space Before and after the first printing character.

TrimLeft
Removes blanks or control characters before the string.

 TrimLeft __fastcall AnsiString () const; 

Returns a new AnsiString TrimLeft Removing Leading spaces and control characters. Use to remove blank space TrimLeft Before the first printing character.

TrimRight

Removes blanks or control characters after the string.

 TrimRight __fastcall AnsiString () const; 

Returns a new AnsiString TrimRight Removing trailing spaces and control characters. Use the TrimRight function to remove blank space after the first printing character.

TStringMbcsByteType
Unique

UpperCase

Convert string to uppercase.

 AnsiString __fastcall UpperCase () const; 

WideChar
WideCharBufSize

Example:

 / * Compile with bcc32 famille.cpp vcl.lib ole2w32.lib * / 

# Include
# Include

Famille class
{
private:
AnsiString FName [10];
AnsiString GetName (int Index);
void SetName (int, AnsiString);
public:
__property AnsiString Names [int Index] = {read = GetName, SetName write =};
Famille () {}
~ Famille () {}
};
Famille AnsiString:: GetName (int i)
{
return FName [i];
}
void Famille:: SetName (int i, const AnsiString s)
{
FName [i] = s;
}
int main ()
{
Famille C;
C. Names [0] = "Steve" / / calls Famille:: SetName ()
. Names [1] = "Amy"
. Names [2] = "Sarah"
. Names [3] = "Andrew"
for (int i = 0; i <= 3; i + +)
{
/ / Calls Famille:: GetName ()
puts (C. Names [i]. c_str ());
}
}

Sprintf functions, swprintf

Syntax
# Include
int sprintf (char * buffer, const char * format [, argument, ...]);
int swprintf (wchar_t * buffer, const wchar_t * format [, argument, ...]);

Description
Create a string from a format.

sprintf accepts a series of arguments, Applied To Each a format specifier in the format string Contained Pointed to by format, and outputs the formatted data to a string.
Applies the first sprintf format specifier to the first argument, the second to the second, and so on. There Must Be the Same number of format specifiers as arguments.

Return Value
On success, sprintf returns the number of bytes output. The return value not does include the terminating null byte in the count.

On error, returns EOF sprintf.

Example:

 # Include 
# Include

int main (void)
{
char buffer [80];

sprintf (buffer, "An Approximation of Pi is% f \ n", M_PI);
puts (buffer);
return 0;
}
Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |