C# এ একটি স্ট্রিং এর শেষ অংশ সরাতে Regex.Replace পদ্ধতি ব্যবহার করুন।
নিচের স্ট্রিং −
string s1 = "Demo Text!";
এখন, আসুন বলি আপনাকে স্ট্রিং থেকে বিস্ময়বোধক চিহ্ন (!) অপসারণ করতে হবে। এটির জন্য শুধুমাত্র প্রতিস্থাপন −
ব্যবহার করে এটিকে খালি করুনSystem.Text.RegularExpressions.Regex.Replace(s1, "!", "");
এখানে সম্পূর্ণ কোড −
উদাহরণ
using System;
using System.Text.RegularExpressions;
namespace Demo {
class Program {
static void Main(string[] args) {
string s1 = "Demo Text!";
// replace the end part
string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "!", "");
Console.WriteLine("\"{0}\"\n\"{1}\"", s1, s2);
}
}
} আউটপুট
"Demo Text!" "Demo Text"