How to replace a character in StringBuilder with C#

2 Answers

0 votes
using System;
using System.Text;

public class Program
{
	public static void Main(string[] args) {
		StringBuilder sb = new StringBuilder("C#-programming-in-the-enterprise");
		char ch = '-';

		for (int i = 0; i < sb.Length; i++) {
			if (sb[i] == ch) {
				sb[i] = ' ';
			}
		}
		Console.WriteLine(sb);
	}
}




/*
  
run:
  
C# programming in the enterprise
  
*/


 

 



answered Jul 18, 2022 by avibootz
0 votes
using System;
using System.Text;

public class Program
{
	public static void Main(string[] args) {
		StringBuilder sb = new StringBuilder("C#-programming-in-the-enterprise");
		char ch = '-';

		string str = sb.ToString().Replace(ch, ' ');
		
		Console.WriteLine(str);
	}
}




/*
  
run:
  
C# programming in the enterprise
  
*/

 



answered Jul 18, 2022 by avibootz

Related questions

1 answer 91 views
1 answer 139 views
1 answer 124 views
2 answers 187 views
2 answers 110 views
3 answers 276 views
...