有关字符串的怀疑 [英] Doubt regarding strings

查看:108
本文介绍了有关字符串的怀疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字符串

1.字符串路径//包含文件保存到的路径

2.字符串名称//包含经常更改的文件的名称

现在我必须以.xlsx格式保存文件,我该如何实现????
:((:((:((:((
----------------------------
我所做的是

xlWorkBook.SaveAs(path +" + fName +.xlsx");

但出现错误:(

请帮助我:)

i have two strings

1 . string path // contains the path to which the file is saved

2 . string name // contains the name of the file which changes frequently

now i have to save the file with .xlsx format , how can i achieve this ???
:(( :(( :(( :((
----------------------------
what i have done is

xlWorkBook.SaveAs(path + "" +fName+".xlsx");

but am getting errors :(

please help me :)

推荐答案

好,现在正确答案:

OK, now the correct answer:

string fileName = string.Format(
    "{0}{1}{2}{3}",
    path,
    System.IO.Path.DirectorySeparatorChar, //important: '\' is incompatible!
    fName,
    ".xlsx");



其他答案未考虑"\"形式的目录分隔符不可移植,因此我无法接受.特别是,它在Unix上不起作用(是的,对Unix的支持是CLI标准的一部分,实际上,可以使用Mono在Linux,Unix,MAC等上使用此代码).

此外,据报道,string.Format比一组字符串串联(使用"+")具有更好的性能.

感谢您关注这些细节.

-SA



Other answers does not take into account that the directory separator in the form of ''\'' is not portable — so I could not accept them. In particular, it won''t work on Unix (yes, support of Unix is a part of CLI standard, in practice, this code can be used on Linux, Unix, MAC, etc. using Mono).

Also, string.Format is reportedly of better performance then a set of string concatenations (using ''+'').

Thank you for attention to these details.

—SA


尝试在路径和文件名之间放置一个"\"字符.

如果那不能解决问题,那么我们需要了解错误消息/异常详细信息.
Try putting a ''\'' character between the path and the file name.

If that doesn''t fix it, then we need to know the error message / exception detail.


这篇关于有关字符串的怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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