-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,045
  • 2
  • 28
  • 41
Charanoglu
  • 1,099
  • 1
  • 9
  • 26

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
  • 68,786
  • 25
  • 88
  • 134
-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
  • 73,987
  • 13
  • 62
  • 116