次の方法で共有


String.Indent(Int32) Method

Definition

Adjusts the indentation of each line of this string based on the value of n, and normalizes line termination characters.

[Android.Runtime.Register("indent", "(I)Ljava/lang/String;", "", ApiSince=34)]
public string Indent (int n);
[<Android.Runtime.Register("indent", "(I)Ljava/lang/String;", "", ApiSince=34)>]
member this.Indent : int -> string

Parameters

n
Int32

number of leading Character#isWhitespace(int) white space characters to add or remove

Returns

string with indentation adjusted and line endings normalized

Attributes

Remarks

Adjusts the indentation of each line of this string based on the value of n, and normalizes line termination characters.

This string is conceptually separated into lines using String#lines(). Each line is then adjusted as described below and then suffixed with a line feed "\n" (U+000A). The resulting lines are then concatenated and returned.

If n > 0 then n spaces (U+0020) are inserted at the beginning of each line.

If n < 0 then up to nCharacter#isWhitespace(int) white space characters are removed from the beginning of each line. If a given line does not contain sufficient white space then all leading Character#isWhitespace(int) white space characters are removed. Each white space character is treated as a single character. In particular, the tab character "\t" (U+0009) is considered a single character; it is not expanded.

If n == 0 then the line remains unchanged. However, line terminators are still normalized.

Added in 12.

Java documentation for java.lang.String.indent(int).

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