Vb.net 按字母顺序排序列表
我怎样才能得到根据“针”按字母顺序排列的链接列表?第272行的排序函数没有提供所需的结果。请帮忙Vb.net 按字母顺序排序列表,vb.net,Vb.net,我怎样才能得到根据“针”按字母顺序排列的链接列表?第272行的排序函数没有提供所需的结果。请帮忙 <script language="VB" runat="server"> Function sectionTitle(ByRef f As String) 'Open a file for reading 'Dim FILENAME As String = Server.MapPath("index.asp") Dim F
<script language="VB" runat="server">
Function sectionTitle(ByRef f As String)
'Open a file for reading
'Dim FILENAME As String = Server.MapPath("index.asp")
Dim FILENAME As String = f
'Get a StreamReader class that can be used to read the file
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)
'Now, read the entire file into a string
Dim contents As String = objStreamReader.ReadToEnd()
'search string for <title>some words</title>
Dim resultText As Match = Regex.Match(contents, "(<title>(?<t>.*?)</title>)")
'put result into new string
Dim HtmlTitle As String = resultText.Groups("t").Value
Return HtmlTitle
' If HtmlTitle <> "" Then
'Response.Write(HtmlTitle)
' Else
'Response.Write("<ul><li>b: " & contents & "</a></li></ul>")
' End If
End Function
Public Class linkItem
Public myName As String
Public myValue As String
Public Sub New(ByVal myName As String, ByVal myValue As String)
Me.myName = myName
Me.myValue = myValue
End Sub 'New
End Class 'linkItem
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Dim mylist As New List(Of linkItem)
Try
For Each d In Directory.GetDirectories(sDir)
'Response.Write("test c")
For Each f In Directory.GetFiles("" & d & "", "index.asp")
'Response.Write("test a")
Dim sTitle As String = sectionTitle(f)
'remove wilbur wright college - from sTitle string
sTitle = Regex.Replace(sTitle, "My College - ", "")
'print section title - must come before search n replace string
f = Regex.Replace(f, "C:\\inetpub\\wwwroot\\mypath\\", "")
'add to list
mylist.Add(New linkItem(f, sTitle))
'print links as list
'Response.Write("<ul><li><a href='" & f & "'>" & sTitle & "</a></li></ul>")
Next
DirSearch(d)
Next
Catch excpt As System.Exception
'Response.Write("test b")
Response.Write(excpt.Message)
End Try
mylist.Sort(Function(p1, p2) p1.myValue.CompareTo(p2.myValue))
mylist.ForEach(AddressOf ProcessLink)
End Sub
Sub ProcessLink(ByVal P As linkItem)
If (True) Then
Response.Write("<ul><li><a href='" & P.myName & "'>" & P.myValue & "</a></li></ul>")
End If
End Sub
</script>
<%
'Dim sDir As New DirectoryInfo(Server.MapPath(""))
Call DirSearch((Server.MapPath("")))
%>
函数节标题(ByRef f作为字符串)
'打开一个文件进行读取
'Dim FILENAME As String=Server.MapPath(“index.asp”)
Dim文件名为String=f
'获取可用于读取文件的StreamReader类
Dim objStreamReader作为StreamReader
objStreamReader=File.OpenText(文件名)
'现在,将整个文件读入字符串
将内容标注为String=objStreamReader.ReadToEnd()
'搜索字符串以查找某些单词
Dim resultText As Match=Regex.Match(内容,(?*?))
'将结果放入新字符串中
Dim HTMLITLE As String=resultText.Groups(“t”).Value
返回HtmlTitle
“如果是HTMLITLE”,则
'Response.Write(HtmlTitle)
”“否则呢
'回答。写(“- b:&contents&“
”)
"完"
端函数
公共类链接项
公共myName作为字符串
作为字符串的公共myValue
Public Sub New(ByVal myName作为字符串,ByVal myValue作为字符串)
Me.myName=myName
Me.myValue=myValue
“新”结束
“结束类”链接项
子目录搜索(ByVal sDir作为字符串)
将d变暗为字符串
作为字符串的Dim f
Dim mylist作为新列表(链接项的列表)
尝试
对于Directory.GetDirectories(sDir)中的每个d
'响应.写入(“测试c”)
对于Directory.GetFiles(“&d&”“index.asp”)中的每个f
'响应.写入(“测试a”)
作为字符串的尺寸针=节标题(f)
'将威尔伯·赖特学院从缝合线中移除
sTitle=Regex.Replace(sTitle,“我的学院-”,“”)
'打印节标题-必须在搜索和替换字符串之前
f=Regex.Replace(f,“C:\\inetpub\\wwwroot\\mypath\\”,“”)
'添加到列表中
mylist.Add(新链接项(f,缝合))
'将链接打印为列表
'响应。写(“”)
下一个
直接搜索(d)
下一个
捕获excpt作为系统异常
'响应.写入(“测试b”)
响应写入(除消息外)
结束尝试
排序(函数(p1,p2)p1.myValue.CompareTo(p2.myValue))
mylist.ForEach(ProcessLink的地址)
端接头
子进程链接(ByVal P作为链接项)
如果(真的)那么
回答。写(“”)
如果结束
端接头
查看界面以帮助完成此操作
基本上,你需要教你的程序使用什么作为你的课程的比较参考点
IComparable将允许您使用该方法
以下是您感兴趣的示例代码:
Public Class Temperature
Implements IComparable
Public Overloads Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
If TypeOf obj Is Temperature Then
Dim temp As Temperature = CType(obj, Temperature)
Return m_value.CompareTo(temp.m_value)
End If
Throw New ArgumentException("object is not a Temperature")
End Function
' The value holder
Protected m_value As Integer
Public Property Value() As Integer
Get
Return m_value
End Get
Set(ByVal Value As Integer)
m_value = Value
End Set
End Property
Public Property Celsius() As Integer
Get
Return (m_value - 32) / 2
End Get
Set(ByVal Value As Integer)
m_value = Value * 2 + 32
End Set
End Property
End Class