0

I have a kind of note which i stored in verbative string like:

string a = @"123123
             456456
             868686";

now i want to change all the spaces and enters that are pressed above(twice) and make it like this:

string a = @"123123456456868686";

What logic should i use?

  • 3
    [`Char.IsWhiteSpace`](https://msdn.microsoft.com/en-us/library/system.char.iswhitespace(v=vs.110).aspx) is your friend. Also, a regex can be handy: `Regex.Replace(s, @"\s+", string.Empty)` – Wiktor Stribiżew Nov 03 '16 at 16:56
  • @L.B You are absolutely right. My apologies. Comment removed. – Jret Nov 03 '16 at 18:13

1 Answers1

0

Just split and then combine you string

var b = string.Concat(a.Split());

or as Wiktor Stribiżew commented

var b = string.Concat(a.Where(c => !char.IsWhiteSpace(c)));
L.B
  • 110,417
  • 19
  • 170
  • 215