Usage of Trim (), TrimStart (), and TrimEnd () in C:
These three methods are used to delete certain characters that appear at the beginning and end of a string. Trim () deletes spaces in the header and tail of a string. The deletion process is from the outside to the inner until a non-space character is encountered, therefore, no matter how many consecutive spaces exist before and after it is deleted. TrimStart () only deletes spaces in the string header. TrimEnd () only removes spaces at the end of the string.
If these three functions carry the parameters of the struct array, they are to delete any character that appears in the struct array. For example, Trim ("abcd ". toCharArray () is to delete the, B, c, or d characters in the header and tail of a string, the deletion process ends until it encounters a character that is neither a nor B nor c nor d.
The most common misunderstanding here is that the "abcd" string is deleted. For example:
String s = "from dual union all ";
S = s. Trim (). TrimEnd ("union all". ToCharArray ());
Some people may think that the final result of s is "from dual", but the real result is "from d ". Note that the delete object executed in this writing method is any character in the character array, rather than a string consisting of these characters!
Common TRIM function usage:
The Trim () function deletes spaces at the beginning and end of a string. Syntax Trim (string) parameter string: string type, which specifies the String return value of the leading and trailing spaces to be deleted. If the function is successfully executed, a string with spaces at the header and tail of the string is deleted. If an error occurs, an empty string ("") is returned (""). If the value of any parameter is NULL, the Trim () function returns NULL.
The TRIM function in SQL is used to remove the character header or end of a string. The most common purpose is to remove the leading or trailing blank spaces. This function has different names in different databases: MySQL: TRIM (), RTRIM (), LTRIM () Oracle: RTRIM (), LTRIM () SQL Server: RTRIM (), the syntax of various trim functions of LTRIM () is as follows: TRIM ([[location] [string to be removed] FROM] string): the possible value of [location] is LEADING (START ), TRAILING (end), or BOTH (start and end ). This function removes the [string to be removed] from the start, end, or end of the string. If we do not list what the [string to be removed] is, the blank space will be removed. LTRIM (string): removes white spaces from the start of all strings. RTRIM (string): removes the white space at the end of all strings.