gpt4 book ai didi

c# - string.Format() 给出 "Input string is not in correct format"

转载 作者:IT王子 更新时间:2023-10-29 03:34:52 26 4
gpt4 key购买 nike

我在这里做错了什么?

string tmp = @"
if (UseImageFiles) {
vCalHeader += ""<td><img onmousedown='' src= '{0}cal_fastreverse.gif' width='13px' height='9' onmouseover='changeBorder(this, 0)' onmouseout='changeBorder(this, 1)' style='border:1px solid white'></td>\n""; //Year scroller (decrease 1 year)
calHeight += 22;
}";

string x = "xter";
tmp = string.Format(tmp, x);

我明白了

Input string was not in correct format

尝试更改 {0} 时。我在 C# 和 WinForms 中执行此操作。

Format Exception was unhandled
Input string was not in correct format

我得到的疑难解答提示:

Make sure your method arguments are in right format. When converting a string to datetime, parse the string to take out the date before putting each variable into the DateTime object.

最佳答案

string.Format() 将每个“{”或“}”视为占位符的一部分(例如您已经使用的“{0}”)。您需要通过将每个字面值加倍来转义它。

所以在你的情况下:

 string tmp = @"
if (UseImageFiles) {{
...
}}";

关于c# - string.Format() 给出 "Input string is not in correct format",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6951479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com