1

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"/>"
2
  • Aren't you misusing InnerText a bit here? Afaik that's for setting text and you're setting markup. Shouldn't you use InnerXml in the first place? And why do you need to write this as concatenation of various strings and characters anyway? The second method should work (if you escape the ") as well. Commented Mar 9, 2009 at 13:12
  • Looking at the 2nd code snippet, I guess your problem is that the doubles quotes need to be escaped? See my answer below. Commented Mar 9, 2009 at 13:18

3 Answers 3

1

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?

Sign up to request clarification or add additional context in comments.

Comments

1

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())

Comments

0

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.

2 Comments

Documentation says that InnerText escapes any < and > that it encounters, since that's what it's for :)
But you're still passing it exactly the same string, so this isn't going to help you...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.