User: alciro    User
 

Programación en C++ Builder

Share |
 Arrays (matrices)
 Punteros
3. Ejemplo de clase en c++
8. Métodos de la clase AnsiString
 Proyectos en C++
 Packages, distribuir una aplicación sin instalación
 Ordenación por intercambio o burbuja
 Funciones de cadenas de caracteres string.h

8. Métodos de la clase AnsiString

Métodos de la clase AnsiString

AnsiCompare
Este método compara dos cadenas AnsiString con distinción entre mayúsculas y minúsculas (case-sensitively).

int __fastcall AnsiCompare(const AnsiString& rhs) const;

Si las dos cadenas son iguales, retorna el valor 0.
Si la cadena que requiere la comparación es menor que la pasada como un argumento, el valor de retorno es negativo. De lo contrario, es mayor que 0.

ConditionReturn Value
S1 > S2> 0
S1 < S2< 0
S1 = S2= 0

Ejemplo:

AnsiString Cadena="Elefante";
ShowMessage (Cadena.AnsiCompare("Elefante")) ; // Respuesta 0
ShowMessage (Cadena.AnsiCompare("Elefantf")) ; // Respuesta -1
ShowMessage (Cadena.AnsiCompare("Elefantd")) ; // Respuesta 1

AnsiCompareIC
Compara la cadena AnsiString a otra cadena especificada sin distinción entre mayúsculas y minúsculas (case insensitively).

int __fastcall AnsiCompareIC (const AnsiString y 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 using the AnsiString comparison operators. AnsiCompare is based on a locale-specific collating order. The return value is shown below:

ConditionReturn Value
S1 > S2> 0
S1 < S2< 0
S1 = S2= 0

AnsiLastChar
AnsiPos
AnsiString
ByteType
c_str
Entrega un puntero a char de los datos de la cadena.

char* __fastcall c_str() const;

CurrToStr
CurrToStrF
Delete
Elimina una parte de la cadena.

void __fastcall Delete(int index, int count);

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

FloatToStrF
FmtLoadStr
Format
FormatFloat
Insert
Agrega un texto a una cadena en la posición que se le indique.

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

Inserts the string str into this AnsiString beginning at the position of index.

IntToHex
Convierte un número en una cadena de formato 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
Mira si una cadena está vacía.

bool __fastcall IsEmpty() const;

Returns true if this AnsiString is empty, false otherwise.

IsLeadByte
IsPathDelimiter
IsTrailByte
LastDelimiter

Length
Entrega la longitud de una cadena en número de caracteres.

int __fastcall Length() const;

LoadStr
LowerCase
Convierte una cadena a minúsculas.

AnsiString __fastcall LowerCase() const;

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

Pos
Entrega la posición que ocupa una subcadena dentro de una cadena.

int __fastcall Pos(const AnsiString& subStr) const;

Returns the index in the AnsiString at which the substring subStr begins. If the substring is not contained in the AnsiString, Pos returns 0.

SetLength

Parte una cadena según la longitud indicada.

void __fastcall SetLength(int newLength);

Truncates the length of the string if newLength is less than the current string length. SetLength does not increase the length of the string.

StringOfChar

Entrega una cadena a partir de un carácter, repitiendolo n veces.

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

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

SubString
Devuelve una subcadena de una cadena comenzando en la posición indicada y según la longitud especificada.

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

Returns a new AnsiString that is a substring of this AnsiString. The substring contains count characters beginning at index.

ToDouble

Convierte una cadena a un número real double. Si no se puede convertir se produce una excepción.

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 DecimalSeparator global 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 doesn't contain a valid value, an EConvertError exception is thrown.

ToInt

Convierte una cadena a un número entero. Si no se puede convertir se produce una excepción.

int __fastcall ToInt() const;

Converts the given string to an integer value and returns the integer. If the string doesn't contain a valid value, an EConvertError exception is thrown.

ToIntDef
Convierte una cadena a un número entero. Si no se puede convertir se asigna un valor por defecto y no se produce una excepción.

int __fastcall ToIntDef(int defaultValue) const;

Converts the given string to an integer value and returns the integer. If the string doesn't contain a valid value, the value given by defaultValue is returned.

Trim
Elimina los espacios en blanco o los caracteres de control antes y después de la cadena.

AnsiString __fastcall Trim() const;

Trim returns a new AnsiString removing leading and trailing spaces and control characters. Use Trim to remove blank space before and after the first printing character.

TrimLeft
Elimina los espacios en blanco o los caracteres de control antes de la cadena.

AnsiString __fastcall TrimLeft() const;

TrimLeft returns a new AnsiString removing leading spaces and control characters. Use TrimLeft to remove blank space before the first printing character.

TrimRight

Elimina los espacios en blanco o los caracteres de control después de la cadena.

AnsiString __fastcall TrimRight() const;

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

TStringMbcsByteType
Unique

UpperCase

Convierte una cadena a mayúsculas.

AnsiString __fastcall UpperCase() const;

WideChar
WideCharBufSize

Ejemplo:

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

#include
#include

class Famille
{
private:
AnsiString FNames[10];
AnsiString GetName(int Index);
void SetName(int, AnsiString);
public:
__property AnsiString Names[int Index] = {read=GetName, write=SetName};
Famille(){}
~Famille(){}
};
AnsiString Famille::GetName(int i)
{
return FNames[i];
}
void Famille::SetName(int i,const AnsiString s)
{
FNames[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());
}
}

Funciones sprintf, swprintf

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

Descripción
Crea una cadena de caracteres a partir de un formato.

sprintf accepts a series of arguments, applies to each a format specifier contained in the format string pointed to by format, and outputs the formatted data to a string.
sprintf applies the first 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 does not include the terminating null byte in the count.

On error, sprintf returns EOF.

Ejemplo:

#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 |