I’ve got a problem which seems to be a real nut. I am using HTMLAgilityPack in order to read in an HTML page and use XPath to select a couple of elements I need. This works fine.
Using XPATH, I’m also trying to select the number that is this DIV (441676).
<div class="info">
Money:
441 676,-<br>
</div>
I manage to select the number, and trim it using this fantastic method:
Fastest way to remove white spaces in string
But whatever I do, the white space between the 441 and 676 won’t disappear.
Trimming white spaces other places works just fine. It is ONLY between the digits that it doesn’t work. Anyone knows what I’m missing here?
It looks to me like you are dealing with a non-breaking space. Using the method you linked to, I have two suggestions for you.
The first is to update your
toExcludearray to include the following character:var str = s.ExceptChars(new[] { ' ', '\t', '\n', '\r','\u00A0'});Note: You should probably move the array to a static global variable, since it never changes and you don’t want to be reallocating it every time you call this function.
Another alternative would be to update your
ExceptCharsfunction to use the Char.IsWhiteSpace function, as follows: