How to remove the middle character from a string in C#

1 Answer

0 votes
using System;

public class Program
{
	public static string removeMiddleChar(string str) {
		int length = str.Length;
		int middleIndex = length / 2;

		return str.Substring(0, middleIndex) + str.Substring(middleIndex + 1);
	}

	public static void Main(string[] args)
	{
		string str = "abcde";

		str = removeMiddleChar(str);

		Console.WriteLine(str);
	}
}



/*
run:
 
abde
 
*/

 



answered Mar 16, 2024 by avibootz

Related questions

2 answers 196 views
1 answer 100 views
1 answer 182 views
1 answer 159 views
1 answer 138 views
1 answer 190 views
...