Archive for tag: trim

Trim function or normalize space in XPath with C#

In XPath we can trim or remove spaces, it doesn't have trim function in XPath 1.0 but can use normalize-space(), it just doesn't trim it doesn't it more thing that as well following is an example:

normalize-space()

//removing spaces from beginning and end
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item1 ') ='Item1']");

//removing only trailing spaces
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item 1 ') ='Item 1']");

//removing more than one spaces and leave just one space between characters or words
NodeIter = nav.Select("/Products/Product/name[normalize-space(' Item    1   2 ') ='Item 1 2']");

 

normalize-space() does more than just trimming spaces.

If you have question don't forget to ask.

Thank you for going through