从字符串中删除白色 [英] removing white from a string

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

问题描述

我正在尝试从字符串中删除空格.我尝试了trim方法,但它没有给我我想要的东西.实际上,字符串包含路径
例如
http://localhost:23766/WebSite2/NewFolder1/ICT部门/MIS和运营部门/软件申请表/萨马布拉/HRC_RC_3052012_final.pdf的人力资源政策审查

Samabula和/HR .....之间有一个空白,我需要删除.由于字符串是动态确定的,因此无法使用诸如string.trim(x,x)之类的索引修饰.

任何帮助都会有很大帮助.

Im trying to remove a space from a string.I have tried trim methods but it does not give me what i want.Actual the string contains a path
eg
http://localhost:23766/WebSite2/NewFolder1/Division of ICT/Dept of MIS and Operations/Software Request Form/Samabula /HR Policy Review for HRC_RC_3052012_final.pdf

There isa white space between Samabula and /HR..... which i need to remove.I can not use the index trim such as string.trim(x,x)since the string is determine dynamically.

Any help would be of great help.

推荐答案



根据您的解释,很容易解决您的问题,我希望您不想中断路径,因此不应更改文件名/文件夹名中的空间.对吗?

请检查以下代码,

Hi,

As per your explanation it is very easy to resolve your issue, i hope you do not want to break the path so space in file name/folder name should not be changed. right ?

Please check below code,

string str = "yourpath";
str.Replace(" /","/");
str.Replace("/ ","/");



谢谢
-Amit Gajjar



Thanks
-Amit Gajjar


简单..
很明显,路径中的"/"之前不允许有空格.
simple..
Its obvious that space should not be allowed before "/" in paths.
mystring.Replace(" /","/");



这里是用"/"代替空格+"/".因此,符号"/"前的空格将被删除,而无论在何处/



Here am replacing space + "/" with "/". So the space preceding symbol "/" will be removed in the string wherever it is/


Use Below code for your problem.. it will definitely solve your problem.


string str = @"http://localhost:23766/WebSite2/NewFolder1/Division of ICT/Dept of MIS and Operations/Software Request Form/Samabula /HR Policy Review for HRC_RC_3052012_final.pdf";
string[] strsplit = str.Split('/');
str =null;
foreach (string item in strsplit) { str = str + item.Trim() + "/"; }


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

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