从一行中分割特定字符 [英] splitting specific characters from a line
本文介绍了从一行中分割特定字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的先生/女士,
在下面带有方括号的路径中,如何获得
文件名"Sample.doc".
[D:\ Employee管理系统\ EMP details11 \ Sample.doc]
Dear Sir/Madam,
here in the below path with square brackets how can i get the
filename "Sample.doc".
[D:\Employee management system\EMP details11\Sample.doc]
推荐答案
这很容易做到.
试试看-使用基本字符串操作 [
This is fairly easy to do.
Give it a try - using Basic String Operations[^] should give you an idea.
If you still run into issues, post them here and someone will help you.
这里是一个快速的技巧,可为您提供解决方案(C#):
Here is one quick hack that gives you the solution (C#):
string test = @"[D:\Employee management system\EMP details11\Sample.doc]";
string res = test.Replace("[", "");
res = test.Replace("]", "");
res = System.IO.Path.GetFileName(res); //res gives you "sample.doc"
VB.NET:
VB.NET:
Dim test As String = "[D:\Employee management system\EMP details11\Sample.doc]"
Dim res As String = test.Replace("[", "")
res = test.Replace("]", "")
res = System.IO.Path.GetFileName(res) 'res gives you "sample.doc"
这是另一个(C#):
and here is another one (C#):
string test = @"[D:\Employee management system\EMP details11\Sample.doc]";
string res = test.Replace("[", "");
res = test.Replace("]", "");
string[] splits = res.Split('\\');
res = splits[splits.Length - 1]; //res gives you "sample.doc"
VB.NET:
VB.NET:
Dim test As String = "[D:\Employee management system\EMP details11\Sample.doc]"
Dim res As String = test.Replace("[", "")
res = test.Replace("]", "")
Dim splits() As String = res.Split(Microsoft.VisualBasic.ChrW(92))
res = splits((splits.Length - 1))'res gives you "sample.doc"
您可以得到
you can get as
string ss=@"D:\Employee management system\EMP details11\Sample.doc";
string[] split = ss.Split(new Char[] { '\\' });
ArrayList al = new ArrayList();
foreach (string s in split)
{
if (s.Trim() != "")
al.Add(s);
}
Console.WriteLine(al[3].ToString());
这篇关于从一行中分割特定字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文