Sdílet prostřednictvím


String.Trim Method

Definition

Returns a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).

[Android.Runtime.Register("trim", "()Ljava/lang/String;", "")]
public string Trim ();
[<Android.Runtime.Register("trim", "()Ljava/lang/String;", "")>]
member this.Trim : unit -> string

Returns

a string whose value is this string, with all leading and trailing space removed, or this string if it has no leading or trailing space.

Attributes

Remarks

Returns a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).

If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes that are not space (as defined above), then a reference to this String object is returned.

Otherwise, if all characters in this string are space (as defined above), then a String object representing an empty string is returned.

Otherwise, let k be the index of the first character in the string whose code is not a space (as defined above) and let m be the index of the last character in the string whose code is not a space (as defined above). A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m + 1).

This method may be used to trim space (as defined above) from the beginning and end of a string.

Java documentation for java.lang.String.trim().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to