-1

I have a string -> 1234,2345,12341,6442

Need to remove 12341 in above string through C# code and my string should be 1234,2345,6442 in C#

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Harry
  • 15
  • 7

1 Answers1

-1

You can do it using simple string replace:

namespace ReplaceExample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("1234,2345,12341,6442".Replace("12341,", string.Empty));
        }
    }
}

Considering that the number to replace may be the last element the comma should not included to replace pattern, so using Regex may be a more elegant solution:

using System.Text.RegularExpressions;    

namespace ReplaceExample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Regex.Replace("1234,2345,12341,6442", @"12341[,]*", string.Empty));
        }
    }
}
isidat
  • 936
  • 10
  • 18