开发者

string.Format() giving "Input string is not in correct format"

开发者 https://www.devze.com 2023-03-26 05:48 出处:网络
What do I do wrong here? string tmp = @\" if (UseImageFiles) { vCalHeader += \"\"<td><img onmousedown=\'\' src= \'{0}cal_fastreverse.gif\' width=\'13px\' height=\'9\' onmouseover=\'changeBor

What do I do wrong here?

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 开发者_JAVA百科year)
        calHeight += 22;
    }";

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

I get

Input string was not in correct format

when trying to change {0}. I am doing this in C# and WinForms.

Format Exception was unhandled

Input string was not in correct format

Troubleshoot tips I get:

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() considers each '{' or '}' to be part of a placeholder (like '{0}' you already use). You need to escape each literal occurrence by doubling it.

So in your case do:

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

精彩评论

暂无评论...
验证码 换一张
取 消