I have a string in linq which is loaded from xml, that attribute or element is optional, but I want to trim the string because the xml file can be written manually like this.
<text>Hello World</text>
or like this
<text>
hello world
<text>
the later will create the new line characters before and afterwards which i want trimming.
I tried to do
QuestionText = (string)query.Element("text").ToString().Trim()
but that crashes the app when that element is not present.
1 Answer