所以我这里有一个 VB.net 字符串,如下所示。
我有另一个字符串 startId
,我希望将其替换在适当的位置。
所以我写了以下几行。
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)
但是我收到输入字符串格式不正确
错误。
我是 vb.net 的新手,似乎无法理解。
请指教。
最佳答案
因为末尾有{\r\n
。 {
表示您要开始一个新元素。左大括号和右大括号是必需的。阅读remarks section .
您还必须将从 String.Format
返回的新字符串分配给字符串变量:
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)
关于vb.net - 为什么 String.Format 给出此字符串的 inputString 未格式化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26779513/