স্ট্রিং থেকে ক্যারেক্টার রিমুভ করতে StringBuilder ক্লাসের Remove() মেথড ব্যবহার করা হয়। স্ট্রিং ইমিউটেবল হওয়ায় সরাসরি পরিবর্তন করা যায় না।
উদাহরণ
using System;
using System.Text;
public class Demo
{
public static void Main(string[] args)
{
string str1 = "Amit";
Console.WriteLine("মূল স্ট্রিং: " + str1);
StringBuilder strBuilder = new StringBuilder(str1);
strBuilder.Remove(3, 1); // ইনডেক্স ৩ থেকে ১ ক্যারেক্টার রিমুভ
str1 = strBuilder.ToString();
Console.WriteLine("ক্যারেক্টার রিমুভ করার পর: " + str1);
}
}
আউটপুট
মূল স্ট্রিং: Amit ক্যারেক্টার রিমুভ করার পর: Ami
Remove(startIndex, length) মেথড নির্দিষ্ট ইনডেক্স থেকে নির্দিষ্ট সংখ্যক ক্যারেক্টার মুছে ফেলে। ইনডেক্স ০-ভিত্তিক।