2.2.3.15 string


Contents

Name

string

Remark

An Origin C string is a null terminated array of characters similar to objects created using the MFC CString class. The Origin C string class includes many useful methods for manipulating strings (text data).

StringArray is type defined as a vector of strings in string.h
See the for a

Hierarchy

Examples

EX1

void string_ex1()
{
	string str = "  abcdefg   ";
	str.TrimRight();//Trim leading whitespace characters from the string
	
	str.TrimLeft();//Trim trailing whitespace characters from the string
	
	int nRet;
	nRet = str.Compare("abcdefg");//Compare the trimmed string with "abcdefg"
	out_int("", nRet); //Return 0 since they are identical
	
	str = str.Left(5); //Extract the leftmost 5 characters 
	
	str = str.Mid(1, 4); //Extract a substring of 4 characters from the 2nd character
	
	nRet = str.Compare("bcde");//Compare the extracted string with "abcdefg"
	out_int("", nRet); //Return 0 since they are identical
	
	nRet = str.Find('d');//Find the index of 'd' in the string 
	out_int("", nRet); //the index is 2(zero based)

}

Header to Include

origin.h

Reference

Members

Name Brief Example
Perform a case-sensitive comparison of this string object with another string.
Perform a case-insensitive comparison of this string object with another string.
Count number of occurances of specified character in string. Support wide characters
Delete a character or characters from a string starting with the character at nIndex. If nCount is longer than the string, the remainder of the string will be removed.
Make this string object an empty string (0 length) and free memory as appropriate.
Search this string for the first match of a single character.
Search this string for the first character that matches any character contained in lpszCharSet.
Find a token in this string
Format and store a series of characters and values in the string
Return a single character specified by an index number.
Retrieve a pointer to the internal character buffer for the string.
Retrieve 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.
Copy the charactors of this string into a byte vector
Return the number of bytes (or number of characters) in this string object. The count does not include a null terminator.
Return the number of tokens in this string where a token is separated by the delimiter specified by chDelimiter.
Return the token at nToken index in a string where a token is separated by the delimiter specified by chDelimiter.
Create a StringArray from this string, this process depend on code page, default is system code page,it can be changed by function set_code_page_for_string_process
Insert a character or substring at the given index within the string.
Test a string object for the empty condition,check whether the string object contains any characters or not.
Test to see whether the string is a valid full path file name or not.
Test to see whether a string object is a valid path or not.The path should be exist.
Extract the leftmost nCount characters from this string object and return a copy of the extracted substring.If nCount exceeds the string length,then the entire string is extracted.
Convert this string object to a lowercase string.
Convert this string object to an uppercase string.
Modify a string to be a valid C identifier name. A valid C Identifier name must begin with a letter and can contain only letters, numbers, and underscore characters.
String pattern matching, any number of wildchars are supported, which can be * or ?.
Extract a substring of length nCount characters from this string object, starting at position nFirst (zero-based).
Use ReleaseBuffer to end use of a buffer allocated by GetBuffer.
Remove instances of the input char from the string. Comparisons for the character are case-sensitive.
Replace a character with another. (Comparison is case-sensitive in all cases.)
Search this string object for the last match of a character.
Extract the rightmost nCount characters from this string object and returns a copy of the extracted substring.If nCount exceeds the string length,then the entire string is extracted.
Overwrite a single character specified by an index number.SetAt will not enlarge the string if the index exceeds the bounds of the existing string.
Set the content of this string from a vector of bytes
Copy a StringArray into this string and separate them with specified delimiter
Search the string for the first occurrence of any character in the specified set lpszCharSet.
Extract characters from the string,starting with the first character,that are in the set of characters identified by lpszCharSet.
Default constructor, creates a new empty string object
Trim leading whitespace characters from the string. It removes newline, space, and tab characters.
Trim trailing whitespace characters from the string. It removes trailing newline, space, and tab characters.
Output the string.
Output the string adding return and newline characters automatically.