কম্পিউটার টিউটোরিয়াল

C#-তে স্ট্রিং-এ লাইন ব্রেক রিপ্লেস কীভাবে করবেন?

ধরুন আমাদের নিচের স্ট্রিং থেকে লাইন ব্রেক, স্পেস এবং ট্যাব স্পেস এলিমিনেট করতে হবে।

Replace() মেথড ব্যবহার করে উদাহরণ

আমরা স্ট্রিংর `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`-ও ব্যবহার করতে পারি। `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
  1. জাভাস্ক্রিপ্ট RegExp ব্যবহার করে স্ট্রিং রিপ্লেস করা

  2. জাভাস্ক্রিপ্ট দিয়ে স্ট্রিং-এ সব ডট কীভাবে রিপ্লেস করবেন?

  3. জাভাস্ক্রিপ্টে স্ট্রিং থেকে টেক্সট রিমুভ করা

  4. Objective-C-এ স্ট্রিং-এ ক্যারেক্টার রিপ্লেস (Replace) করার পদ্ধতি