📄 string.h
字号:
for( n = 0; n < saColors.GetSize(); n++ )
{
strToken = saColors[n];
nToken = strColors.FindToken(strToken, '|');
printf("%s is token %d\n", strToken, nToken);
}
Parameters:
lpcszToken = pointer to a string representing the token to find
chDelimiter = character to use as the delimiter
Return:
The zero based index of the token if found, -1 if token was not found
SeeAlso:
string::GetNumTokens, string::GetToken
*/
int FindToken(LPCSTR lpcszToken, char chDelimiter = 0);
/**
Remarks:
Makes this string object an empty string (0 length) and
frees memory as appropriate.
Example:
string str("abc");
str.Empty();
ASSERT(str.GetLength( ) == 0);
Parameters:
None.
Return:
None.
SeeAlso:
string::IsEmpty
*/
void Empty( );
/**
Remarks:
Tests a string object for the empty condition.
Tests whether a string object contains any characters.
Example:
string str;
ASSERT(str.IsEmpty());
Parameters:
None.
Return:
Nonzero if the string object has 0 length; otherwise 0.
SeeAlso:
string::GetLength
*/
BOOL IsEmpty( );
/**
Remarks:
This member function extracts characters from the string,
starting with the first character, that are in the set of
characters identified by lpszCharSet. If the first
character of the string is not in the character set, then
SpanIncluding returns an empty string. Otherwise, it returns
a sequence of consecutive characters which are in the set.
Example:
string str1("cabinet");
string str2=str1.SpanIncluding("abc");
ASSERT(str2.Compare("cab")==0);
string str3=str1.SpanIncluding("xyz");
ASSERT(str3.IsEmpty());
Parameters:
lpszCharSet = A string interpreted as a set of characters.
Return:
A substring that contains characters in the string that are
in lpszCharSet, beginning with the first character in the
string and ending when a character is found in the string
that is not in lpszCharSet. SpanIncluding returns an empty
substring if the first character in the string is not in the
specified set.
SeeAlso:
string::SpanExcluding
*/
string SpanIncluding( LPCSTR lpszCharSet );
/**
Remarks:
This member function searches the string for the first
occurrence of any character in the specified set lpszCharSet.
SpanExcluding extracts and returns all characters preceding
the first occurrence of a character from lpszCharSet
(in other words, the character from lpszCharSet and all
characters following it in the string, are not returned). If
no character from lpszCharSet is found in the string, then
SpanExcluding returns the entire string.
Example:
string str1("Hello World! Goodbye!");
string str2("Hello World Goodbye");
string str3=str1.SpanExcluding(".!?");
string str4=str2.SpanExcluding(".!?");
ASSERT(str3.Compare("Hello World")==0);
ASSERT(str4.Compare("Hello World Goodbye")==0);
Parameters:
lpszCharSet = A string interpreted as a set of characters.
Return:
A substring that contains characters in the string that are
not in lpszCharSet, starting with the first character in the
string and up to but excluding the first character in the
string that is found lpszCharSet). It returns the entire
string if no character in lpszCharSet is found in the string.
SeeAlso:
string::SpanIncluding
*/
string SpanExcluding( LPCSTR lpszCharSet );
/**
Remarks:
This overloaded member function replaces a character with
another. (Comparison is case-sensitive in all cases.)
Example:
string str("A+B+C+");
ASSERT(str.Replace('+','-')==3);
Parameters:
chOld = The character to be replaced by chNew.
chNew = The character replacing chOld.
Return:
The number of replaced instances of the character.
Zero if the string isn't changed.
SeeAlso:
string::Remove
*/
int Replace( char chOld, char chNew );
/**
Remarks:
This overloaded member function replaces instances of the
substring lpszOld with instances of the string lpszNew.
Example:
string str("Today is Friday");
ASSERT(str.Replace("Friday","Monday")==1);
ASSERT(str.Compare("Today is Monday")==0);
Parameters:
lpszOld = A pointer to a string containing the characters to
be replaced by lpszNew.
lpszNew = A pointer to a string containing the characters
replacing lpszOld.
Return:
The number of replaced instances of the character. Zero if
the string isn't changed.
SeeAlso:
string::Remove
*/
int Replace( LPCSTR lpszOld, LPCSTR lpszNew );
/**
Remarks:
This overloaded member function replaces instances of the
all characters as specified by lpszOneOf with the character chNew.
If the resulted string has repeated occurance of chNew, they are
stripped so that only one is left
Example:
string str("123 \t456, 789;\n\r1212");
str.Replace(" \t\n\r,;",',');
ASSERT(str.Compare("123,456,789,1212")==0);
Parameters:
lpszOneOf = A pointer to a string containing the characters that all are to
be replaced by chNew.
chNew = The character replacing lpszOneOf.
Return:
The number of replaced instances of the chNew. Zero if no replacement
took place.
*/
int Replace( LPCSTR lpszOneOf, char chNew );
/**
Remarks:
This member function removes instances of ch from the string.
Comparisons for the character are case-sensitive.
Example:
string str("apple");
str.Remove('p');
ASSERT(str.Compare("ale")==0);
Parameters:
ch = The character to be removed from a string.
Return:
The count of characters removed from the string.
Zero if the string isn't changed.
SeeAlso:
string::Replace
*/
int Remove( char ch );
/**
Remarks:
This member function searches this string for the first
character that matches any character contained in lpszCharSet.
Example:
string str("abcdef");
ASSERT(str.FindOneOf("xd")==3); // 'd' is first match
Parameters:
lpszCharSet = string containing characters for matching.
Return:
The zero-based index of the first character in this string that is
also in lpszCharSet; -1 if there is no match.
SeeAlso:
string::Find
*/
int FindOneOf( LPCSTR lpszCharSet );
/**
Remarks:
This method retrieves a pointer to the internal character buffer for the string.
If you use the pointer returned by GetBuffer to change the string contents,
you must call ReleaseBuffer before using any other string methods.
Example:
string str = "abcdefg";
char *p = str.GetBuffer( 20 );
out_str( p ); //output should be "abcdefg"
str.ReleaseBuffer();
Parameters:
nMinBufLength = Specifies the minimum size of the character buffer in characters.
This value does not include space for a null terminator.
Return:
This is an LPTSTR pointer to the character buffer of the null-terminated object.
SeeAlso:
string::ReleaseBuffer.
*/
char* GetBuffer( int nMinBufLength );
/**
Remarks:
This method retrieves a pointer to the internal character buffer for the string,
truncating or growing its length, if necessary, to exactly match the length
specified in nNewLength.
Example:
string str;
char* pstr = str.GetBufferSetLength(3);
pstr[0] = 'I';
pstr[1] = 'c';
pstr[2] = 'e';
out_str(str); //output should be "Ice"
Parameters:
nNewLength = Specifies the exact size of the string character buffer in characters.
Return:
This is an LPTSTR pointer to the character buffer of the null-terminated object.
*/
char* GetBufferSetLength( int nNewLength );
/**
Remarks:
Use ReleaseBuffer to end use of a buffer allocated by GetBuffer.
Example:
string str = "abcdefg";
char *p = str.GetBuffer( 20 );
str.ReleaseBuffer();
Parameters:
nNewLength = The new length of the string in characters, not counting a null terminator.
If the string is null-terminated, the -1 default value sets the string size to the
current length of the string.
Return:
None.
SeeAlso:
string::GetBuffer
*/
void ReleaseBuffer( int nNewLength = -1 );
/**
Remarks:
String pattern matching, any number of wildchars are supported, which can be * or ?.
Example:
string str = "abcdefg";
ASSERT(str.Match("ab*"));
ASSERT(str.Match("a*c*f?"));
ASSERT(str.Match("a*d*"));
ASSERT(str.Match("?*e*f?"));
Parameters:
strPattern = the string will be matched.
Return:
TRUE if the provided pattern matches the string.
*/
BOOL Match( LPCSTR strPattern, BOOL bCaseSensitive = FALSE );
/**
Remarks:
This member function tests a string object is a valid or
invalid path.
Example:
string strPath="c:\\Program Files";
ASSERT(strPath.IsPath());
Parameters:
None.
Return:
returns TRUE if the string object is a "path" that exists.
*/
BOOL IsPath( );
/**
Remarks:
This member function tests to see if the string is a valid full path file name
Example:
string strFile("c:\\Program Files\\Originlab\\origin70.exe");
ASSERT(strFile.IsFile());
Parameters:
None.
Return:
returns TRUE if the string is a filename that exist
*/
BOOL IsFile( );
/**
Remarks:
Modify a string to be a valid C identifier name.
A C Identifier name must begin with a letter and can contain only letters,
numbers, and underscore characters.
Parameters:
cPrefixIf1stCharNumber = If not zero and the string begins with a number then this character will be
inserted before the first character. If the first character of the string is not a digit or if
the specified prefix character is not a letter or underscore then this argument will have no effect.
Return:
None
Example:
string str = "23 * this & this";
printf("Before: %s\n", str);
str.MakeValidCName('a'); // prefix with 'a', delete all spaces, and delete '*' and '&'
printf("After: %s\n", str);
*/
void MakeValidCName(char cPrefixIf1stCharNumber=0);
};
////////////////////////////////////////////////////////////////////
#pragma dll(kernel32, system)
// GJL 11/18/02 v7.0437 ADD_ANSI_C_STRING_FUNCS1
/** >Character/String Manipulation
The lstrcpy (alias strcpy) function copies a string to a buffer.
Example:
char szStr[80];
string str1 = "Here is some text";
// Copy str1 to szStr:
lstrcpy(szStr, str1);
out_str(szStr);
Parameters:
lpString1=Pointer to the destination buffer to receive the contents of the string pointed to by the lpString2 parameter.
The buffer must be large enough to contain the string, including the terminating null character.
lpString=Pointer to the null-terminated source string to be copied.
Return:
If the function succeeds, the return value is a pointer to the destination buffer. If the function fails,
the return value is NULL.
*/
LPSTR WINAPI lstrcpy(LPSTR lpString1, LPCSTR lpString2);
/** >Character/String Manipulation
The lstrcat (alias strcat) function appends one string to another.
Example:
char szStr[80] = "This is the first part. ";
string str1 = "This is the second part.";
// Concatenate:
lstrcat(szStr, str1);
out_str(szStr);
Parameters:
lpString1=Pointer to a null-terminated string. The buffer must be large enough to contain both strings.
lpString2=Pointer to the null-terminated string to be appended to the string specified in the lpString1 parameter.
Return:
If the function succeeds, the return value is a pointer to the buffer. If the function fails, the return value is NULL.
*/
LPSTR WINAPI lstrcat(LPSTR lpString1, LPCSTR lpString2);
/** >Character/String Manipulation
The lstrlen (alias strlen) function returns the length of a string in bytes.
Example:
string str1 = "Hello World!";
int len = lstrlen(str1); // len is 12 (the length of str1).
out_int("The length is ", len);
Parameters:
lpString=Pointer to a null-terminated string.
Return:
the length of the string (not including zero termination).
*/
int WINAPI lstrlen(LPCSTR lpString);
/** >Character/String Manipulation
The lstrcpyn (alias strncpy) function copies a specified number of characters from a source string into a buffer.
Parameters:
lpString1=Pointer to a buffer into which the function copies characters. The buffer must be large enough to contain
the number of characters specified by iMaxLength, including room for a terminating null character.
lpString2=Pointer to a null-terminated string from which the function copies characters.
iMaxLength=Specifies the number of characters to be copied from the string pointed to by lpString2 into the buffer
pointed to by lpString1, including a terminating null character.
Return:
If the function succeeds, the return value is a pointer to the buffer. If the function fails, the return value is NULL.
Example:
string str1 = "Hello World!";
char szStr[80];
lstrcpyn(szStr, str1, 5);
out_str(szStr); // Should be "Hell"
*/
LPSTR WINAPI lstrcpyn(LPSTR lpString1, LPCSTR lpString2, int iMaxLength);
/** >Character/String Manipulation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -