"C # Zhanza" 1 String type (2)

Source: Internet
Author: User
Tags rtrim

4 "Trim whitespace

Trim is also a method node of string

C # Examples are as follows:

There are three trim nodes for Trim,trimend and TrimStart in C #, and the latter two do not need to be described.

If you do, Trim () is equivalent to removing the trailing spaces.

These three methods are used to remove some characters from the tail of a string. Trim () removes whitespace from the head and tail of the string, removing the process from the outside to the inside until a non-whitespace character is encountered, so that no matter how many contiguous spaces are removed before and after. TrimStart () removes only the space of the string's head. TrimEnd () deletes only the trailing spaces of the string.

      if these three functions take the parameters of a character array, Removes any characters that appear in the character array. such as trim ("ABCD"). ToCharArray ()) is the deletion of the string at the head and tail of a or B or C or D characters, the process of deletion until the end of a word that is neither a nor B nor C nor D characters.
      The most misleading misunderstanding here is that the "ABCD" string is removed. The following example:
          string s = "from dual union ALL";
          s = S.trim (). TRIMEND ("union All". ToCharArray ());
      Some may think that the end result of the s above is "from dual", but the real result is "from D". It is important to note that this type of deletion is performed by any character that appears in the character array, rather than the string that the words connect prompt together!  


General Trim Function Usage:
The Trim () feature removes the string header and trailing spaces. The syntax trim (string) parameter string:string type, which specifies the string return value of the header and trailing spaces to remove. When the function executes successfully, returns a string that deletes the header and trailing spaces of string string, returning an empty string ("") when an error occurs.   If the value of any parameter is Null,trim () the function returns NULL. The TRIM function in ======================================================================== SQL is used to remove the word head or end of a string. The most common use is to remove whitespace from the beginning or end of the word. This function has different names in different repositories: Mysql:trim (), RTRIM (), LTRIM () Oracle:rtrim (), LTRIM () SQL Server:rtrim (), LTRIM () various TRIM The syntax of the function is as follows: TRIM ([[position] [string to remove] from] string: Possible values for [position] are leading (start), TRAILING (end), or BOTH (beginning and ending). This function removes the string [to be removed] from the beginning, end, or beginning and end of the string.   If we don't list what the [string to remove] is, the blanks will be removed.   LTRIM (String): Removes all whitespace from the beginning of the string. RTRIM (String): Removes all whitespace from the end of the string.

"C # Zhanza" 1 String type (2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.