-1

I have this string:

PO Box 162, Ferny Hills
QLD 4055
Brisbane

which contains these character:

enter image description here

I want remove this charactes, so I tried:

info.Address = dd[i].InnerText
                    .Replace("\n", " ")
                    .Replace(" ", "")
                    .Replace(",", ", ");

but didn't works, I get all the character of the string attached. I'm expecting this result: PO Box 162, Ferny Hills QLD 4055 Brisbane.

smn.tino
  • 2,272
  • 4
  • 32
  • 41
Charanoglu
  • 1,229
  • 2
  • 11
  • 30

2 Answers2

0

Well, you replaced all blanks by nothing ( .Replace(" ", "") ). What did you expect? Now all your blanks are gone.

If you don't want that, don't do it.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
-1

you can try like this, by splitting and trimming the string to remove spaces and join them back by newline

var address = dd[i].InnerText.Split(new[] { Environment.NewLine })
                    .Select(s => s.Trim());    
info.Address = String.Join(Environment.NewLine, address);
Rahul
  • 76,197
  • 13
  • 71
  • 125