2

So i have a VB.net String here that looks as such below. I have another string startId that i wish is substituted in the appropriate places. So i wrote the following lines.

Dim jsonPayloadHeaderFormat As String = "Content-Type: application/json;charset=UTF-8" & "\r\n" & "Content-ID: {0}" & "\r\n" & "Content-Disposition: attachment; filename={0}" & "\r\n" & "{" & "\r\n"
    String.Format(jsonPayloadHeaderFormat, startId)

But i get a input string not in correct format error. I am new to vb.net and can't seem to get it. Please advise.

4
  • what is the string in the variable startId Commented Nov 6, 2014 at 12:30
  • 3
    You have an open { at the end. If it's intentional, then see ways to escape { in string.format function in vb. Commented Nov 6, 2014 at 12:31
  • 2
    Because of the {\r\n at the end. { indidcates that you want to begin a new element. Opening and closing braces are required. Commented Nov 6, 2014 at 12:33
  • 1
    or if the intention is to emit a { character, it must be escaped, using {{ Commented Nov 6, 2014 at 12:36

1 Answer 1

2

Because of the {\r\n at the end. { indidcates that you want to begin a new element. Opening and closing braces are required. Read the remarks section.

You also have to assign the new string which is returned from String.Format to a string variable:

Dim jsonPayloadHeaderFormat As String = "Content-Type: application/json;charset=UTF-8" & "\r\n" & "Content-ID: {0}" & "\r\n" & "Content-Disposition: attachment; filename={0}" & "\r\n\r\n"
Dim result As String = String.Format(jsonPayloadHeaderFormat, startId) 
Sign up to request clarification or add additional context in comments.

Comments

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.