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

String string.h functions

char * stpcpy (char * dest, const char * src); < br / > wchar * _wcspcpy (WCHAR * dest, const WCHAR * src);

Copy a string into other.

_stpcpy copies the string src to dest, stopping after reaching the null termination character src.

stpcpy returns a pointer to the character null termination for dest.

If you define UNICODE, _wcspcpy returns a pointer to the completion of the wchar_t string null character dest.

 # include < string.h > # include < stdio.h > int main (void) {char string [10]};
   char * s = "abcdefghi";

   stpcpy (string, s);
   ("printf("%s\n", string);
   return 0;
}

< br / > char * strcat (char * dest, const char * src); < br / > wchar_t * wcscat (wchar_t * dest, const wchar_t * src); < br / > unsigned char * _mbscat (unsigned char * dest, const unsigned char * src);

Adds a string to other.

strcat adds a copy of src at the end of dest. The length of the resulting string is strlen (dest) + strlen (src).

strcat returns a pointer to the strings concatenated.

 # include < string.h > # include < stdio.h > int main (void) {char destination [25]};
   char * blank = "", * c = "C++", * Borland = "Borland";

   strcpy (destination, Borland);
   strcat (destination, blank);
   strcat (destination, c);

   ("printf("%s\n", destination);
   return 0;
}

char * strchr (const char * s, int c); / * C only * / < br / > const char * strchr (const char * s, int c); / / C ++ only < br / > char * strchr (char * s, int c); / / C ++ only < br / > wchar_t * wcschr (const wchar_t * s, int c); < br / > unsigned char * _mbschr (const unsigned char * s, unsigned int c); < br / > < br / > analyzes a string in search of the first occurrence of a character determined. < br / > < br / > strchr analyses a string in the direction of progress, in search of a particular character. strchr finds the first occurrence of the character c in string s. The null terminator is considered to be part of the chain. < br / > < br / > for example:< br / > < br / > strchr (RTS, 0) < br / > < br / > returns a pointer to the null character for termination of the transaction chain suspicious. < br / > < br / > < em > strchr returns a pointer to the first occurrence of the character c in s, if c does not occur in s, strchr returns a null.

 # include < string.h > # include < stdio.h > int main (void) {char string [15]};
   char * ptr, c = 'r';

   strcpy(String,_"This_is_a_string");
   PTR = strchr (string, c);
   If (ptr) printf("The_character_%c_is_at_position:_%d\n",_c,_ptr-string);
   else printf("The_character_was_not_found\n");
   return 0;
}

int strcmp (const char * s1, const char * s2); < br / > int wcscmp (const wchar_t * s1, const wchar_t * s2); < br / > int _mbscmp (const unsigned char * s1, const unsigned char * s2);

Compares a string with other.

strcmp compares the contents of s1 with s2, from the first character of each string and continues with the following characters until the corresponding characters differ or to reach the end of the string.

Return value

if s1...return value is...
less than s2 < 0
the same as s2 == 0
greater than s2 > 0
 # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "aaa", * buf2 = "bbb", * buf3 = "ccc";}
	int ptr;

	PTR = strcmp (buf1, buf2);
	If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");
	else printf("buffer_2_is_less_than_buffer_1\n");

   PTR = strcmp (buf2, buf3);
   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_3\n");
   else printf("buffer_2_is_less_than_buffer_3\n");

   return 0;
}

int strcmpi (const char * s1, const char * s2); < br / > int _wcscmpi (const wchar_t * s1, const wchar_t * s2);

Compares one string to another, without distinction between uppercase and lowercase.

strcmpi makes a comparison of the contents of s1 with s2, without distinction between uppercase and lowercase (like stricmp - implemented as a macro).

Return value

if s1...strcmpi returns a value that is...
less than s2 < 0
the same as s2 == 0
greater than s2 > 0
 / * strncmpi example * / # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "BBB", * buf2 = "bbb";}
   int ptr;

   PTR = strcmpi (buf1, buf2);

   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");

   If (ptr < 0) printf("buffer_2_is_less_than_buffer_1\n");

   If (ptr == 0) printf("buffer_2_equals_buffer_1\n");

   return 0;
}

int strcmp (const char * s1, const char * s2); < br / > int wcscmp (const wchar_t * s1, const wchar_t * s2); < br / > int _mbscmp (const unsigned char * s1, const unsigned char * s2);

Compares a string with other.

strcmp compares the contents of s1 with s2, from the first character of each string and continues with the following characters until the corresponding characters differ or to reach the end of the string.

Return value

if s1...return value is...
less than s2 < 0
the same as s2 == 0
greater than s2 > 0
 # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "aaa", * buf2 = "bbb", * buf3 = "ccc";}
	int ptr;

	PTR = strcmp (buf1, buf2);
	If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");
	else printf("buffer_2_is_less_than_buffer_1\n");

   PTR = strcmp (buf2, buf3);
   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_3\n");
   else printf("buffer_2_is_less_than_buffer_3\n");

   return 0;
}

char * strcpy (char * dest, const char * src); < br / > wchar_t * wcscpy (wchar_t * dest, const wchar_t * src); < br / > unsigned char * _mbscpy (unsigned char * dest, const unsigned char * src); < br / > < br / > copy a string into other. < br / > < br / > copies string src to dest, stopping after moving the null character completion. < br / > < br / > strcpy returns dest.

 # include < stdio.h > # include < string.h > int main (void) {char string [10]};
   char * s = "abcdefghi";

   strcpy (string, s);
   ("printf("%s\n", string);
   return 0;
}

size_t strlen (const char * s); < br / > size_t wcslen (const wchar_t * s); < br / > size_t _mbslen (const unsigned char * s); < br / > size_t _mbstrlen (const char * s) < br / > < br / > calculate the length of a string. < br / > < br / > strlen to calculate the length of s. < br / > < br / > strlen returns the number of characters s, not counting the null termination character.

 # include < stdio.h > # include < string.h > int main (void) {char * string = "Borland International";}

   ("printf("%d\n", strlen (string));
   return 0;
}

char * strlwr (char * s); < br / > wchar_t * _wcslwr (wchar_t * s); < br / > unsigned char * _mbslwr (unsigned char * s); < br / > < br / > converts the letters of a string in lowercase. < br / > < br / > strlwr converts the letters capitalized on the string s in lowercase with local category LC_CTYPE. For regional settings, C performs the conversion is from the upper case letters (A to Z) lowercase letters (a to z). < br / > < br / > strlwr returns a pointer to the string s.

 # include < stdio.h > # include < string.h > int main (void) {char * string = "Borland International";}

   printf("string_prior_to_strlwr:_%s\n",_string);
   strlwr (string);
   printf("string_after_strlwr:_%s\n",_string);
   return 0;
}

char * strncat (char * dest, const char * src, size_t maxlen); < br / > wchar_t * wcsncat (wchar_t * dest, const wchar_t * src, size_t maxlen); < br / > unsigned char * _mbsncat (unsigned char * dest, const unsigned char * src, size_t maxlen); < br / > unsigned char * _mbsnbcat (unsigned char * __dest, const unsigned char * __src, _SIZE_T __maxlen); < br / > < br / > add a portion of a string to other. < br / > < br / > strncat copies specified characters maxlen of src at the end of dest, and then adds a null character. The maximum length of the resulting string is strlen (dest) + maxlen. < br / > < br / > for _mbsnbcat, if the second byte of the character of 2 bytes is zero, the first byte of this character is considered invalid. < br / > < br / > these four functions behave identically and only differ with regard to the type of arguments and types returned. < br / > < br / > strncat returns dest.

 # include < string.h > # include < stdio.h > int main (void) {char destination [25]};
   char * source = "States";

   strcpy (destination, "United");
   strncat(destination,_source,_7);
   ("printf("%s\n", destination);
   return 0;
}

int strncmp (const char * s1, const char * s2, size_t maxlen); < br / > int wcsncmp (const wchar_t * s1, const wchar_t * s2, size_t maxlen); < br / > int _mbsncmp (const char * s1 unsigned, unsigned const char * s2, size_t maxlen); < br / > # define _mbccmp (__s1, __s2) _mbsncmp ((__s1), (_ s2), 1) < br / > < br / > compares a portion of a string to a part of other. < br / > < br / > strncmp makes the same comparison to strcmp, but it exceeds the number of characters indicated in maxlen. It starts with the first character of each string and continues with the following characters until a difference is or was examined maxlen characters. < br / > < br / > strncmp returns an integer value based on the result of the comparison of s1 (or part of it) to s2 (or part of it):

< 0 if s1 is less than s2
== 0 if s1 equals s2
> 0 if s1 is greater than s2

 # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "aaabbb", * buf2 = "bbbccc", * buf3 = "ccc";}
   int ptr;

   PTR = strncmp(buf2,buf1,3);
   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");
   else printf("buffer_2_is_less_than_buffer_1\n");

   PTR = strncmp(buf2,buf3,3);
   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_3\n");
   else printf("buffer_2_is_less_than_buffer_3\n");

   (0) return;

}

int strncmpi(const_char_*_s1,_const_char_*_s2,_size_t_n); < br / > int wcsncmpi (const wchar_t * s1, const wchar_t * s2, size_t n); < br / > < br / > compares a portion of a string to one part of another, without distinction between uppercase and lowercase. < br / > < br / > strncmpi compares s1 to s2for a maximum length of n bytes, starting with the first character of each string, and continue with the following characters until the corresponding characters differ or until discussed n characters. The comparison distinguishes between uppercase and lowercase. (Strncmpi is the same as strnicmp - implemented as a macro). Returns a value (< 0, 0, or > 0) on the basis of the result of compare s1 (or part of it) to s2 (or portion thereof). < br / > < br / > if s1 is... strncmpi returns a value that is...< br / > < br / >

less than s2 < 0
the same as s2 == 0
greater than s2 > 0

 # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "BBBccc", * buf2 = "bbbccc";}
   int ptr;

   PTR = strncmpi(buf2,buf1,3);

   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");

   If (ptr < 0) printf("buffer_2_is_less_than_buffer_1\n");

   If (ptr == 0) printf("buffer_2_equals_buffer_1\n");

   return 0;
}

char * strncpy(char_*_dest,_const_char_*_src,_size_t_maxlen); < br / > wchar_t * wcsncpy (wchar_t * dest, const wchar_t * src, size_t maxlen); < br / > unsigned char * _mbsncpy (unsigned char * dest, const unsigned char * src, size_t maxlen); < br / > < br / > copy a specified number of bytes of one string in another, truncating or stuffed as it may be necessary. < br / > < br / > strncpy copies up to src dest maxlen characterstruncating dest with the insertion of null. The chain of destiny, dest, not can be finished in null if the length of orig is maxlen or more. < br / > < br / > strncpy returns dest.

 # include # include int main (void) {char string [10]};
   char * s = "abcdefghi";

   strncpy(String,_str1,_3);
   String [3] = '\0';
   ("printf("%s\n", string);
   return 0;
}

int strnicmp (const char * s1, const char * s2, size_t maxlen); < br / > int _wcsnicmp (const wchar_t * s1, const wchar_t * s2, size_t maxlen); < br / > int _mbsnicmp (const char * s1 unsigned, unsigned const char * s2, size_t maxlen); < br / > < br / > compares a portion of a string to one part of another, without distinction between uppercase and lowercase. < br / > < br / > strnicmp compares s1 to s2, for a maximum length of bytes maxlen, starting with the first character of each string, and continue with the following characters until the corresponding characters differ or until the end of the string is reached. The comparison makes no distinction between uppercase and lowercase. < br / > < br / > returns a value (< 0, 0, or > 0) depending on the outcome of the comparison of s1 (or part thereof) to s2 (or portion thereof). < br / > < br / >

if s1...strnicmp returns a value that is...
less than s2 < 0
the same as s2 == 0
greater than s2 > 0

 # include < string.h > # include < stdio.h > int main (void) {char * buf1 = "BBBccc", * buf2 = "bbbccc";}
   int ptr;

   PTR = strnicmp(buf2,_buf1,_3);

   If (ptr > 0) printf("buffer_2_is_greater_than_buffer_1\n");

   If (ptr < 0) printf("buffer_2_is_less_than_buffer_1\n");

   If (ptr == 0) printf("buffer_2_equals_buffer_1\n");

   return 0;
}

char * strnset (char * s, int ch, size_t n); < br / > wchar_t * _wcsnset (wchar_t * s, wchar_t ch, size_t n); < br / > unsigned char * _mbsnset (unsigned char * s, unsigned int ch, size_t n); < br / > < br / > establishes a certain n number of characters ch of a chain. < br / > < br / > strnset copy the character ch in the first n bytes of the string s. < br / > < br / > if n > strlen (s)then, strlen (s) replace b. Stops when established n characters, or a null character is found. < br / > < br / > each of these functions return s.

 # include < stdio.h > # include < string.h > int main (void) {char * string = "abcdefghijklmnopqrstuvwxyz";}
   char letter = 'x';

   printf("string_before_strnset:_%s\n",_string);
   strnset(String,_letter,_13);
   printf("string_after_strnset:_%s\n",_string);

   return 0;
}

char * strpbrk(const_char_*_s1,_const_char_*_s2); / * C only * / < br / > const char * strpbrk (const char * s1, const char * s2); / / C ++ only < br / > char * strpbrk (char * s1, const char * s2); / / C ++ only < br / > wchar_t * wcspbrk (const wchar_t * s1, const wchar_t * s2); < br / > unsigned char * _mbspbrk (const unsigned char * s1, const unsigned char * S2); < br / > < br / > analyzes a string in search of the first appearance of any carácharacter of a given set. < br / > < br / > strpbrk analyzes a string, s1 for the first occurrence of any character in s2. < br / > < br / > < em > strpbrk returns a pointer to the first occurrence of any of the characters in s2. If s1 s2 is not no coincidence, strpbrk returns a null.

 # include # include int main (void) {char * string1 = "abcdefghijklmnopqrstuvwxyz";}
   char * string2 = "onm";
   char * ptr;

   PTR = strpbrk (string1, string2);

   If (ptr) printf("strpbrk_found_first_character:_%c\n",_*ptr);
   else printf("strpbrk_didn't_find_character_in_set\n");

   return 0;
}

char * strrchr (const char * s, int c); / * C only * / < br / > const char * strrchr (const char * s, int c); / / C ++ only < br / > char * strrchr (char * s, int c); / / C ++ only < br / > wchar_t * wcsrchr (const wchar_t * s, wchar_t c); < br / > unsigned char * _mbsrchr (const unsigned char * s, unsigned int c); < br / > < br / > analyzes a string in search of the last occurrence of a character determined. < br / > < br / >strrchr analyzes a string in the opposite direction, in search of a particular character. strrchr finds the last occurrence of the character c in string s. The null terminator is considered as part of the network. < br / > < br / > strrchr returns a pointer to the last occurrence of the character c if c does not occur in s, strrchr returns a null.

 # include < string.h > # include < stdio.h > int main (void) {char string [15]};
   char * ptr, c = 'r';

   strcpy(String,_"This_is_a_string");
   PTR = strrchr (string, c);
   If (ptr) printf("The_character_%c_is_at_position:_%d\n",_c,_ptr-string);
   else printf("The_character_was_not_found\n");
   return 0;
}

char * strrev (char * s); < br / > wchar_t * _wcsrev (wchar_t * s); < br / > unsigned char * _mbsrev (unsigned char * s); < br / > < br / > invests a chain. < br / > < br / > strrev changes all characters in a string to reverse the order, except the null character termination. (For example, could change string\0 to gnirts\0). < br / > < br / > strrev returns a pointer to the string reversed.

 # include < string.h > # include < stdio.h > int main (void) {char * forward = "string";}

   printf("Before_strrev():_%s\n",_forward);
   strrev (forward);
   printf("After_strrev():_%s\n",_forward);
   return 0;
}

char * strset (char * s, int ch); < br / > wchar_t * _wcsset (wchar_t * s, wchar_t ch); < br / > unsigned char * _mbsset (unsigned char * s, unsigned int ch); < br / > < br / > sets all characters in a string to a character determined. < br / > < br / > strset establishes that all characters in the string s to character ch. Is left when the null termination character is located. < br / > < br / > strset returns s.

 # include < stdio.h > # include < string.h > int main (void) {char string [10] = "123456789";}
   char symbol = 'c';

   printf("Before_strset():_%s\n",_string);
   strset (string, symbol);
   printf("After_strset():_%s\n",_string);
   return 0;
}

char * strpos() (const char * s1, const char * s2); / * C only * / < br / > const char * strpos() (const char * s1, const char * s2); / / C ++ only < br / > char * strpos() (const char * s1, const char * s2); / / C ++ only < br / > wchar_t * wcsstr (const wchar_t * s1, const wchar_t * s2); < br / > unsigned char * _mbsstr (const unsigned char * s1, const unsigned char * S2);

Analyzes a string in the occurrence of a substring search given.

strpos() explores s1 to the first occurrence of the substring s2.

strpos() returns a pointer to the element of s1, s2, where starts (s1 s2 points). If s2 does not occur in s1, strpos() returns a null.

 # include < stdio.h > # include < string.h > int main (void) {char * s = "Borland International", * t = "nation", * ptr;}

   PTR = strpos() (s, t);
   printf("The_substring_is:_%s\n",_ptr);
   return 0;
}

< br / > char * strupr (char * s); < br / > wchar_t * _wcsupr (wchar_t * s); < br / > unsigned char * _mbsupr (unsigned char * s);

Converts the lowercase a string in uppercase.

strupr converts lowercase letters in the string s capitalized according to LC_CTYPE locale category present. conversion is of lowercase letters (a - z) uppercase letters (A to Z). Other characters unchanged.

strupr returns s.

 # include < stdio.h > # include < string.h > int main (void) {char * string = "abcdefghijklmnopqrstuvwxyz", * ptr;}

   / * converts string to upper case characters * / ptr = strupr (string);
   ("printf("%s\n", ptr);
   return 0;
}

Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |