+ 1
How can I improve this code ?
I'm trying to solve the symbols codecoach using c#, but when I use Regex it gives spaces. And it fails all the test cases.using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace SoloLearn { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string result = Regex.Replace(input, "[^a-zA-Z0-9_]+"," "); Console.WriteLine(result); } } }
2 Answers
+ 1
input.Trim() or result.Trim() depending on where you wanna elimnate the space
+ 1
string result =input.Replace(" ","");