The collection of string functions

Started by sukishan, Jul 12, 2009, 06:31 PM

Previous topic - Next topic

sukishan

The collection of string functions included in windows to calculate string length, copy string, concatenate strings and compare strings are listed below:

lstrcmpi - Compares two strings, ignoring case.

lstrcmp – Compares two strings.

lstrcpyn - Copies one string to another, with a maximum length.

lstrcpy - Copies one string to another.

lstrlen - Gets the length of a string in characters.


lstrcmpi
Compares two character strings. The comparison is not case sensitive.

Syntax

int lstrcmpi(LPSTR lpszString1,LPSTR lpszString2);

The first parameter lpszString1 is the pointer to the first null-terminated string to be compared. The second parameter lpszString2 is the pointer to the second null-terminated string to be compared. This function returns a negative value if the function succeeds and the string that lpszString1 points to is less than the string that lpszString2 points to. Returns a positive value if the string that lpszString1 points to is greater than the string that lpszString2 points to. Returns zero if the strings are equal. The lstrcmpi function compares two wide strings by checking the first characters against each other, the second characters against each other, and so on until it finds an inequality or reaches the ends of the strings. Similarly two wide strings can be compared using the function lstrcmpiW and also the wide character string can be represented using LPCWSTR (long pointer to wide character string).


lstrcmp

Compares two strings. The comparison is case sensitive.

Syntax

int lstrcmp(LPSTR lpszString1,LPSTR lpszString2);

The first parameter lpszString1 is the Pointer to the first null-terminated wide string to be compared. The second parameter lpszString2 is the Pointer to the second null-terminated wide string to be compared. Returns a negative value if the function succeeds and the string that lpszString1 points to is less than the string that lpszString2 points to. Returns a positive value if the string that lpszString1 points to is greater than the string that lpszString2 points to. This function returns zero if the strings are equal. The lstrcmp function compares two strings by checking the first characters against each other, the second characters against each other, and so on until it finds an inequality or reaches the ends of the strings. Similarly two wide strings can be compared ignoring case using the function lstrcmpW.


lstrcpy

Copies a string to a buffer.

Syntax

LPSTR lstrcpy(LPSTR lpszString1,LPSTR lpszString2);

The first parameter lpszString1 is the Pointer to a buffer to receive the contents of the string pointed to by the lpszString2 parameter. The buffer must be large enough to contain the string, including the terminating wide null character. The second parameter lpszString2 is the pointer to the null-terminated wide string to be copied. This function returns a pointer to the buffer. Similarly two wide strings can be copied using the function lstrcpyW.


lstrcpyn
Copies a string to a buffer, up to a specified number of characters.

Syntax

LPSTR lstrcpyn(LPSTR lpszString1,LPSTR lpszString2,int iMaxLength);

The first parameter lpszString1 is the pointer to a buffer to receive the contents of the string that the lpszString2 parameter points to. The buffer must be large enough to contain the string, including the terminating wide null character. The second parameter lpszString2 is the pointer to the null-terminated string to be copied. The third parameter iMaxLength gives the maximum number of characters to copy, including a terminating null character. This function returns a pointer to the buffer. If iMaxLength is nonzero, lstrcpyn always inserts a terminating null character in the destination string, which could result in the source string being truncated. Similarly lstrcpynW copies a wide string to a buffer, up to a specified number of wide characters.


lstrlen

Retrieves the length of the specified string.

Syntax

int lstrlen(LPSTR lpszString);

The first parameter lpszString is the pointer to a null-terminated wide string. If the function succeeds, the return value specifies the length of the string. Similarly lstrlenW retrieves the length of the specified wide string.
A good beginning makes a good ending