একটি StringBuilder সাফ করতে, Clear() পদ্ধতি ব্যবহার করুন।
ধরা যাক আমরা নিচের StringBuilder −
সেট করেছিstring[] myStr = { "One", "Two", "Three", "Four" };
StringBuilder str = new StringBuilder("We will print now...").AppendLine(); এখন, StringBuilder −
সাফ করতে Clear() পদ্ধতি ব্যবহার করুনstr.Clear();
আসুন সম্পূর্ণ কোডটি দেখি -
উদাহরণ
using System;
using System.Text;
public class Demo {
public static void Main() {
// string array
string[] myStr = { "One", "Two", "Three", "Four" };
StringBuilder str = new StringBuilder("We will print now...").AppendLine();
// foreach loop to append elements
foreach (string item in myStr) {
str.Append(item).AppendLine();
}
Console.WriteLine(str.ToString());
int len = str.Length;
Console.WriteLine("Length: "+len);
// clearing
str.Clear();
int len2 = str.Length;
Console.WriteLine("Length after using Clear: "+len2);
Console.ReadLine();
}
} আউটপুট
We will print now... One Two Three Four Length: 40 Length after using Clear: 0