要求去掉,后缀名。
如果谁还能过滤掉其他格式只留TXT格式的文件,再去掉后缀就perfect了
15 个解决方案
#1
System.IO.Path.GetFileNameWithoutExtension()
#2
string[] fileName = { "myfile.dll", "myfile1.dll", "myfile.txt" };
string result=string.Empty;
foreach (string s in fileName)
{
if (!s.Contains(".txt"))
result += System.IO.Path.GetFileNameWithoutExtension(s) + "<br/>";
else
result += s+"<br/>";
}
Response.Write(result);
输出:
myfile
myfile1
myfile.txt
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
#3
If System.IO.Path.GetExtension("C:\a.txt") = ".txt" Then
'XXXX
End If
#4
List<string> list = new List<string>();
foreach (string item in comboBox1.Items)
list.Add(item.ToString());
comboBox1.Items.Clear();
foreach (string item in list.Where(x => x.EndsWith(".txt")))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
foreach (string item in comboBox1.Items)
list.Add(item.ToString());
comboBox1.Items.Clear();
foreach (string item in list.Where(x => x.EndsWith(".txt")))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
#5
我题目有图的哦,别漏了。是过滤出TEXT去掉COMBOX显示的后缀名,
#6
楼上打错字了。。我只要combox显示TXT文件,还要去掉后缀。
#7
string[] fileName = { "myfile.dll", "myfile1.dll", "myfile.txt" };
foreach (string s in fileName)
{
if (s.Contains(".txt"))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(s));
}
你要的结果。、
#8
1,我用的是VB.NET
2.combox是需要搜索的,不是固定几个文件的
2.combox是需要搜索的,不是固定几个文件的
#9
#10
之前的还没达到自己的要求吗?去掉扩展名用System.IO.Path.GetFileNameWithoutExtension() 方法是最合适的,处理一下绑定,另外建立一个集合就可以了。
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles
Dim ds = From o In fi
Select Path.GetFileNameWithoutExtension(o.Name)
ComboBox2.DataSource = ds.ToList
End Sub
End Class
#11
有问题啊。Select Path.GetFileNameWithoutExtension(o.Name)
#12
你用的是不是vs2010?
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles
Dim ds As New List(Of String)
For Each o In fi
ds.Add(Path.GetFileNameWithoutExtension(o.Name))
Next
ComboBox2.DataSource = ds.ToList
End Sub
End Class
#13
不错 后缀解决了
筛选只要TXT格式的,能实现吗
感谢
筛选只要TXT格式的,能实现吗
感谢
#14
筛选扩展名,之前的那个帖子回过的。
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles("*.txt")
Dim ds As New List(Of String)
For Each o In fi
ds.Add(Path.GetFileNameWithoutExtension(o.Name))
Next
ComboBox2.DataSource = ds
End Sub
End Class
#15
#1
System.IO.Path.GetFileNameWithoutExtension()
#2
string[] fileName = { "myfile.dll", "myfile1.dll", "myfile.txt" };
string result=string.Empty;
foreach (string s in fileName)
{
if (!s.Contains(".txt"))
result += System.IO.Path.GetFileNameWithoutExtension(s) + "<br/>";
else
result += s+"<br/>";
}
Response.Write(result);
输出:
myfile
myfile1
myfile.txt
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
#3
If System.IO.Path.GetExtension("C:\a.txt") = ".txt" Then
'XXXX
End If
#4
List<string> list = new List<string>();
foreach (string item in comboBox1.Items)
list.Add(item.ToString());
comboBox1.Items.Clear();
foreach (string item in list.Where(x => x.EndsWith(".txt")))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
foreach (string item in comboBox1.Items)
list.Add(item.ToString());
comboBox1.Items.Clear();
foreach (string item in list.Where(x => x.EndsWith(".txt")))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
#5
我题目有图的哦,别漏了。是过滤出TEXT去掉COMBOX显示的后缀名,
#6
楼上打错字了。。我只要combox显示TXT文件,还要去掉后缀。
#7
string[] fileName = { "myfile.dll", "myfile1.dll", "myfile.txt" };
foreach (string s in fileName)
{
if (s.Contains(".txt"))
comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(s));
}
你要的结果。、
#8
1,我用的是VB.NET
2.combox是需要搜索的,不是固定几个文件的
2.combox是需要搜索的,不是固定几个文件的
#9
#10
之前的还没达到自己的要求吗?去掉扩展名用System.IO.Path.GetFileNameWithoutExtension() 方法是最合适的,处理一下绑定,另外建立一个集合就可以了。
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles
Dim ds = From o In fi
Select Path.GetFileNameWithoutExtension(o.Name)
ComboBox2.DataSource = ds.ToList
End Sub
End Class
#11
有问题啊。Select Path.GetFileNameWithoutExtension(o.Name)
#12
你用的是不是vs2010?
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles
Dim ds As New List(Of String)
For Each o In fi
ds.Add(Path.GetFileNameWithoutExtension(o.Name))
Next
ComboBox2.DataSource = ds.ToList
End Sub
End Class
#13
不错 后缀解决了
筛选只要TXT格式的,能实现吗
感谢
筛选只要TXT格式的,能实现吗
感谢
#14
筛选扩展名,之前的那个帖子回过的。
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim di As New DirectoryInfo("D:\NewNetDisk\我的微盘")
ComboBox1.DataSource = di.GetDirectories()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fi = CType(ComboBox1.SelectedValue, DirectoryInfo).GetFiles("*.txt")
Dim ds As New List(Of String)
For Each o In fi
ds.Add(Path.GetFileNameWithoutExtension(o.Name))
Next
ComboBox2.DataSource = ds
End Sub
End Class