Search code examples
c#htmlxpathcharactereuro

XPath, how to delete Euro sign unnecessary characters?


How do i select the text in the span tag that excludes those unnecessary "&nbsp" characters? I need only the number (euro character at the end would be nice, but it's not a must). Note that the numbers change, they are not the same.

<span class="price">15.900&nbsp;€</span>

Solution

  • If you use C# and XPath then assuming you write your XPath expression as a C# string you can use "translate(//span[@class = 'price'], '\u00A0', '')".

    Working sample (in Javascript) is

    console.log(document.evaluate("translate(//span[@class = 'price'], '\u00A0', '')", document, null, XPathResult.ANY_TYPE, null).stringValue);
    <span class="price">15.900&nbsp;€</span>