如何修剪我的FTP字符串 [英] How do I trim my FTP string
本文介绍了如何修剪我的FTP字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FTPAddress来自foreach循环。
FTPAddress =ftp:// me @ localhost / newfolder / newfolder1 /
myFTP string = FTPAddress + file
i希望将其保存在本地驱动器中
newfolder / newfolder1 / file
我的问题是如何拆分FTPAddress字符串?
解决方案
使用正则表达式:
private static 正则表达式regex = 新正则表达式(
^(?< Host>。* @。*?)/(?< Path>。*)
,
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
这会将您的字符串分为两组:Host和Path。 - 你只想要路径。
谢谢OriginalGriff,但如何使用它:(
string s = ftp:// me @ localhost / newfolder / newfolder1 /;
匹配m = splitFTP.Match(s);
if (m.Success)
{
Console.WriteLine(m.Groups [ Host]。Value);
Console.WriteLine(m.Groups [ 路径]。值);
}
...
私有 静态正则表达式splitFTP = 新正则表达式( ^(?< Host>。* @。*?)/(?< Path>。* )
,
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled);将打印:
ftp:// me @ localhost
newfolder / newfolder1 /
FTPAddress is coming from foreach loop.
FTPAddress="ftp://me@localhost/newfolder/newfolder1/"
myFTP string = FTPAddress+file
i want to save it in local drive as
newfolder/newfolder1/file
My question is how do i split the FTPAddress string?
解决方案
Use a regex:
private static Regex regex = new Regex( "^(?<Host>.*@.*?)/(?<Path>.*)
", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled );
This spilts your string into two groups: Host and Path. - you want the Path only.
"thank you OriginalGriff, But how to use it :("
string s = "ftp://me@localhost/newfolder/newfolder1/"; Match m = splitFTP.Match(s); if (m.Success) { Console.WriteLine(m.Groups["Host"].Value); Console.WriteLine(m.Groups["Path"].Value); } ... private static Regex splitFTP = new Regex("^(?<Host>.*@.*?)/(?<Path>.*)
", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);Will print:
ftp://me@localhost newfolder/newfolder1/
这篇关于如何修剪我的FTP字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文