StringBuilder.Clear 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 StringBuilder 인스턴스에서 모든 문자를 제거합니다.
public:
System::Text::StringBuilder ^ Clear();
public System.Text.StringBuilder Clear();
member this.Clear : unit -> System.Text.StringBuilder
Public Function Clear () As StringBuilder
반환
0인 개체 Length 입니다.
예제
다음 예제에서는 문자열로 개체를 StringBuilder 인스턴스화하고 메서드를 Clear 호출한 다음 새 문자열을 추가합니다.
using System;
using System.Text;
public class Class1
{
public static void Main()
{
StringBuilder sb = new StringBuilder("This is a string.");
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length);
sb.Clear();
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length);
sb.Append("This is a second string.");
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length);
}
}
// The example displays the following output:
// This is a string. (17 characters)
// (0 characters)
// This is a second string. (24 characters)
open System.Text
let sb = StringBuilder "This is a string."
printfn $"{sb} ({sb.Length} characters)"
sb.Clear() |> ignore
printfn $"{sb} ({sb.Length} characters)"
sb.Append "This is a second string." |> ignore
printfn $"{sb} ({sb.Length} characters)"
// The example displays the following output:
// This is a string. (17 characters)
// (0 characters)
// This is a second string. (24 characters)
Imports System.Text
Module Example
Public Sub Main()
Dim sb As New StringBuilder("This is a string.")
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length)
sb.Clear()
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length)
sb.Append("This is a second string.")
Console.WriteLine("{0} ({1} characters)", sb.ToString(), sb.Length)
End Sub
End Module
' The example displays the following output:
' This is a string. (17 characters)
' (0 characters)
' This is a second string. (24 characters)
설명
Clear 는 현재 인스턴스의 속성을 0으로 설정하는 Length 것과 동일한 편리한 메서드입니다.