ধরুন, আমরা নিচের স্ট্রিং str1 থেকে হোয়াইটস্পেস সরাতে চাই।
string str1 = "Brad Pitt";
এখন, Regex Replace ব্যবহার করে হোয়াইটস্পেসকে খালি দিয়ে প্রতিস্থাপন করুন। এখানে System.Text.RegularExpressions ব্যবহার করা হয়েছে।
string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", "");
সম্পূর্ণ উদাহরণটি নিচে দেখুন।
উদাহরণ
using System; using System.Text.RegularExpressions; namespace Demo { class Program { static void Main(string[] args) { string str1 = "Brad Pitt"; Console.WriteLine(str1); string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", ""); Console.WriteLine(str2); } } }আউটপুট
Brad Pitt BradPitt