c# - 询问用户在 C# 控制台上导出文件的路径
问题描述
我是编程新手,我正在尝试将创建 txt 文件的路径添加到字符串变量中。但是,如果可以使用 Replace 或 Concat 完成,我做错了。我从未在 C# 上使用过它。这是我到目前为止所做的:
string path = @"###";
do
{
Console.Write("Insert the path in oder to export data: ");
string temp = Console.ReadLine();
}
while (String.IsNullOrEmpty(path));
path = path.Replace("###", "temp");
解决方案
以下行
path = path.Replace("###", "temp");
###
用文字字符串替换路径中的部分temp
。
在操作结束时,变量的内容将为“temp”。path
你根本不需要做 a Replace
。反而,
string path = string.Empty;
do
{
Console.Write("Insert the path in oder to export data: ");
path = Console.ReadLine();
}
while (String.IsNullOrEmpty(path));
将用户输入的路径分配到您的path
变量中。
推荐阅读
- java - 尝试从通过 java Process 执行的 shell 脚本保存文件时,文件始终为空
- c - 如何从使用 ctypes 在 python 中由 MSVC 编译的 dll 调用函数?
- c - 如何修复仅在 MacOS High Sierra (10.13.6) 上出现的 malloc 错误?
- c# - NLog 从我的机器写入所有目标,但无法写入应用服务器上的数据库目标
- python - SQL Server Management Studio v18.6 中的 Python/R
- javascript - Firebase 实时数据库不响应 HTML 表单联系人提交
- c - 在未使用的符号上获取 SEGFAULT
- xpath - google sheet,importxml函数显示了一个blo
- node.js - 谷歌云存储权限仅对某些对象
- python - fileobj.flush() 是否保证 os.stat() 被更新?