ধরা যাক আমরা নিচের স্ট্রিং 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