文件路径中的空白问题 [英] White Space Problem in file path

查看:83
本文介绍了文件路径中的空白问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个控制台应用程序,该应用程序读取图像文件的路径,然后将其转换为灰度.
该应用程序可以在不包含空格的文件路径下正常运行,但是如果路径包含空格,则该应用程序将失败.
该如何纠正?

感谢您的时间.

I''ve developed a console application that reads path of image file and then converts it into grayscale.
The application works fine with file path that does not contain white spaces, but fails if path contains white space.
How to rectify this?

Thanks for your time.

推荐答案

假设您的路径类似于C:\Users\Nikhil\My Documents\filename.jpg,则您的命令应为:
Assuming your path is something like C:\Users\Nikhil\My Documents\filename.jpg then your command should be:
program "C:\Users\Nikhil\My Documents\filename.jpg"


请注意路径周围的引号字符.


Note the quote characters around the path.


可能会有所帮助,

May be this will help,

string path= @"File Path";
path= path.Replace(" " , "");



C#中还有一个很好的方法String.Trim()

path.Trim();

但是Trim将从字符串的开头和结尾删除所有空格字符,但



and there is also a good method in C#, String.Trim()

path.Trim();

but Trim will removes all whitespace characters from the start and the end of the string but


这篇关于文件路径中的空白问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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