ধরা যাক নিচের স্ট্রিং থেকে লাইন ব্রেক, স্পেস এবং ট্যাব স্পেস বাদ দিতে হবে।
remove.jpg
উদাহরণ
আমরা এটি করার জন্য স্ট্রিং এর Replace() এক্সটেনশন পদ্ধতি ব্যবহার করতে পারি।
using System;
namespace DemoApplication {
class Program {
static void Main(string[] args) {
string testString = "Hello \n\r beautiful \n\t world";
string replacedValue = testString.Replace("\n\r", "_").Replace("\n\t", "_");
Console.WriteLine(replacedValue);
Console.ReadLine();
}
}
} আউটপুট
উপরের কোডের আউটপুট হল
Hello _ beautiful _ world
উদাহরণ
আমরা একই অপারেশন সঞ্চালনের জন্য Regex ব্যবহার করতে পারি। Regex System.Text.RegularExpressions নামস্থানে উপলব্ধ৷
৷using System;
using System.Text.RegularExpressions;
namespace DemoApplication {
class Program {
static void Main(string[] args) {
string testString = "Hello \n\r beautiful \n\t world";
string replacedValue = Regex.Replace(testString, @"\n\r|\n\t", "_");
Console.WriteLine(replacedValue);
Console.ReadLine();
}
}
} আউটপুট
উপরের কোডের আউটপুট হল
Hello _ beautiful _ world