错误的输入字符串格式不正确 [英] error input string not in correct format

查看:73
本文介绍了错误的输入字符串格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只是想创建一个名称为当前日期的文件,并检查该文件是否存在.如果存在,则向该文件中写入一些文本,否则将某些数据附加到该文件中.

我写的代码是

Hi,

i am just trying to create a file with its name as current date and checking whether the file is existing or not.if existing i am writing some text to the file otherwise i am appending some data to the file.

the code i wrote is

StringBuilder  log=new StringBuilder ();
            
            string path= string.Format(@"C:/Documents and Settings/aj99823/Desktop/project/{yyyy-mm-dd}.txt",System.DateTime .Now .Date);
            
            if (!File.Exists(path))
            {
                log = new StringBuilder (path);
                File.WriteAllText(path, commaDelimitedText.ToString ()); 
            }
            else
            {
                File.AppendAllText(path, commaDelimitedText.ToString());
            }



它给我错误,说输入字符串的格式不正确...
谁能请我帮忙........... ??????



its giving me error saying input string is not in correct format...
can anyone pleae help me...........??????

推荐答案

看我能解决吗?我在本地尝试,但遇到相同的错误,新的修改如下:

look man i solve it; i try it locally and i get the same error and the new modifications are below:

StringBuilder log = new StringBuilder();

        //string path = string.Format(@"C:\Tester\Lottery_Windows\{yyyy-mm-dd}.txt", System.DateTime.Now.Date);
        string path = @"C:/Documents and Settings/aj99823/Desktop/project/" + DateTime.Now.ToString("yyyy-MM-dd");

        if (!File.Exists(path))
        {
            log = new StringBuilder(path);
            File.WriteAllText(path, "Hello World");
        }
        else
        {
            File.AppendAllText(path, "Hello World");
        }



如果这对您有帮助,请评价
最好的问候



if this help you please rate
best regards


错误是由于路径字符串构造时的强制转换问题引起的.更新的代码应为:

Error is due to casting issue at path string construction. Updated code should be:

string path= string.Format(@"C:/Documents and Settings/aj99823/Desktop/project/{yyyy-mm-dd}.txt",System.DateTime.Now.ToString("yyyy-MM-dd ));



应该可以.



It should work.


这篇关于错误的输入字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆