File name with prefix and number

社会主义新天地 提交于 2021-02-11 15:10:22

问题


i have this problem, I want create this filename of xml file:

NOHEL+number.xml

The number is from variable number, where i added +1 always when i send file out. NOHEL is prefix. Exapmle:

NOHEL1.xml
NOHEL2.xml
NOHEL3.xml

And i want give there...

string strFileName = @"C:\\Users\\L\\Desktop\\NOHEL+number.xml";

Have you any ideas?


回答1:


Try this:

string strFileName = @"C:\Users\L\Desktop\NOHEL" + number + ".xml";

By the way, you don't need to escape characters with \ when you have @.




回答2:


You can use

string.Format(@"C:\Users\L\Desktop\NOHEL{0}.xml", number) 

or

@"C:\Users\L\Desktop\NOHEL" + number + ".xml".

And there is no need to make double slash when you use @ symbol.



来源:https://stackoverflow.com/questions/18381556/file-name-with-prefix-and-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!