tags:

views:

829

answers:

3

Need help with reading special characters within my VB code. ASCII code Char(34) = " works fine but Char(60) = < and Char(62) = > are not being read.

My Code

node.FirstChild.InnerText = Chr(60) & "httpRuntime executionTimeout=" & Chr(34) & "999999" & Chr(34) & " maxRequestLength=" & Chr(34) & "2097151" & Chr(34) & "/" & Chr(62)

Without ASCII Code

'node.FirstChild.InnerText = "<httpRuntime executionTimeout="999999" maxRequestLength="2097151"/>"
A: 

You'll need to give more information about how you're "seeing" the results. In my experience, problems with this are as likely to be about viewing strings in the debugger as getting the right strings in the first place.

I don't really see why you need to use Chr(60) etc at all, other than for the quotes. What happens when you just use < and > in your code?

I strongly suggest you dump the string out to the console rather than using the debugger - the debugger tries to show you how you could represent the string in code, rather than showing you the contents verbatim.

Of course, if this is XML then I'd expect serializing the XML out again to end up escaping the < and > - again, more information about what you're trying to do would be helpful. The absolute ideal (IMO) would be a short but complete program demonstrating the problem - a small console app which does one thing, and a description of what you want it to do instead.

Jon Skeet
Documentation says that InnerText escapes any < and > that it encounters, since that's what it's for :)
Joey
But you're still passing it exactly the same string, so this isn't going to help you...
Rowland Shaw
Indeed. I'm trying to understand what the questioner is really after here...
Jon Skeet
+1  A: 

Maybe this doesn't answer your question, but you could use two double quotes to escape the quotes character in VB.NET:

node.FirstChild.InnerText = _
    "<httpRuntime executionTimeout=""999999"" maxRequestLength=""2097151"" />"

I'm just guessing: you could use the String.Format method for your purposes:

 node.FirstChild.InnerText = _
    String.Format( _
        "<httpRuntime executionTimeout=""{0}"" maxRequestLength=""{1}"" />", _
        timeoutValue.ToString(), reqLenValue.ToString())
splattne
+1  A: 

Are you trying to modify a Config file? Try:-

node.FirstChild.InnerXml =  "<httpRuntime executionTimeout=""999999"" maxRequestLength=""2097151"" />"

Note all that Chr marlarky is unnecessary, were you trying to avoid < and > being encoded as XML entities?

AnthonyWJones
the InnerXML vs. InnerText worked.
MG