ALTE DOCUMENTE
|
|||||||||
In C character strings are represented by a sequence of bytes finished by a trailing zero byte. For example, if you got:
char *Name = "lcc-win32";
You will have in memory something like this:
l |
c |
c |
- |
w |
i |
n |
3 |
2 |
0 |
108 |
99 |
99 |
45 |
119 |
105 |
110 |
51 |
50 |
0 |
We will have at each of the position of the string array a byte containing a number: the ASCII equivalent of a letter. The array will be followed by a zero byte. Zero is not an ASCII character, and can't appear in character strings, so it means that the string finishes there.
This design is quite ancient, and dates to the beginning of the C language. It has several flaws, as you can imme 727j94h diately see:
The most frequently used function of this library are:
int len = strlen("Some character string");
Note that the length of the string is the number of characters without counting the trailing zero. The physical length of the string includes this zero byte however, and this has been (and will be) the source of an infinite number of bugs!
a == b |
strcmp(a,b) == 0 |
a < b |
strcmp(a,b) < 0 |
a >= b |
strcmp(a,b) >= 0 |
l |
c |
c |
w |
i |
n |
c |
o |
m |
p |
i |
l |
e |
r | |||||
Function |
Purpose |
strcat |
Appends strings. |
strchr |
Find the first occurrence of character in a string |
strrchr |
Find the last occurrence of a character in a string |
strcmp |
Compares two strings |
strncmp |
Compare strings up to a maximum length |
strnicmp |
Compare strings up to a maximum length ignoring case |
strcol |
Compare strings using locale-specific information. |
strcpy |
Copy a string into another |
strcspn |
Find a substring in a string |
strupr |
Convert string to upper case |
strlwr |
Convert string to lower case |
strerror |
Get a system error message (strerror) or prints a user-supplied error message (_strerror). |
strlen |
Find the length of a string |
strncat |
Append characters of a string. |
strncpy |
Copy strings up to a maximum length |
strpbrk |
Scan strings for characters in specified character sets. |
strspn |
Find the first substring |
strstr |
Find a substring |
stristr |
Find a string ignoring case. |
strtok |
Find the next token in a string |
strdup |
Duplicate a string. Uses malloc. |
strrev |
Reverse characters in a string |
strtrim |
Eliminate redundant blanks from a string. |
strset |
Set characters in a string to a character. |
You will find the details in the online documentation.
Besides these functions in the standard C library, the operating system itself provides quite a few other functions that relate to strings. Besides some relicts of the 16 bit past like lstrcat and others, we find really useful functions, especially for UNICODE handling.
CharLower |
CharLowerBuff |
CharNext |
CharNextExA |
CharPrev |
CharPrevExA |
CharToOem |
CharToOemBuff |
CharUpper |
CharUpperBuff |
CompareString |
FoldString |
GetStringTypeA |
GetStringTypeEx |
GetStringTypeW |
IsCharAlpha |
IsCharAlphaNumeric |
IsCharLower |
IsCharUpper |
LoadString |
lstrcat |
lstrcmp |
lstrcmpi |
lstrcpy |
lstrcpyn |
lstrlen |
MultiByteToWideChar |
OemToChar |
OemToCharBuff |
WideCharToMultiByte |
wsprintf |
wvsprintf |
|