VB.NET-从字符串中获取第二个超链接并设置为LinkLabel文本属性



我有一个工具,可以接收电子邮件并将数据排序到适当的字段中。在电子邮件中,通常有两个超链接启动IBM notes中的票证编辑器。一个是本地链接,一个是服务器链接。下面的代码可以获得本地链接,因为它是第一个包含"notes://"的超链接,但我也需要为服务器获取一个,它也以"notes:/"开头;。

For i = 0 To lines.Count + 1
If lines(i).StartsWith("notes://") Then
StartLine = i
Exit For
End If
Next
link_OpenRequestUsingNotes.Text = lines(StartLine)

我想写一些代码来检查关于它的行,看看它是否匹配特定的字符串,也许是Regex?

对于本地链接,它需要查找:"使用Notes客户端(本地副本(";

对于服务器链接,它需要查找:"使用Notes客户端(服务器(:";

超链接位于该文本下方,因此需要查找这些超链接,然后在下一行获取文本。

然后,这些链接被设置为两个链接标签的文本,用户可以按下并转到该链接。

如果有人能帮我找到获得服务器链接的方法,我将不胜感激。

您可以使用以下代码:

link_OpenRequestUsingNotes_Local.Text = "" 'fields for local link
link_OpenRequestUsingNotes_Server.Text = "" 'field for server link
For i = 0 To lines.Count - 1
If lines(i).StartsWith("using a Notes client (local replica)") Then
link_OpenRequestUsingNotes_Local.Text = lines(i + 1)
ElseIf lines(i).StartsWith("using a Notes client (Server)")
link_OpenRequestUsingNotes_Server.Text = lines(i + 1)
End If
If link_OpenRequestUsingNotes_Local.Text <> "" AndAlso link_OpenRequestUsingNotes_Server.Text <> "" Then
Exit For
End If
Next i

您可以使用这样的代码来查找前两个链接:

Dim notes = Function(x) x.StartsWith("notes://")
Dim index As Integer = lines.FindIndex(notes)
If index <> -1 AndAlso index < (lines.Count - 1) Then
Dim firstLink As String = lines(index + 1)
' ... do something with "firstLink"...
Debug.Print(firstLink)
index = lines.FindIndex(index + 2, notes)
If index <> -1 AndAlso index < (lines.Count - 1) Then
Dim secondLink As String = lines(index + 1)
' ... do something with "secondLink"...
Debug.Print(secondLink)
End If
End If

我自己设法修复了它

只需在i上加1(StartLine=i+1(即可转到下面的行!

'Notes Server Link
For i = 0 To lines.Count - 1
If lines(i).StartsWith("Click here to open the request using a Notes client (Server):") Then
StartLine = i + 1
Exit For
End If
Next
link_OpenServerLink.Text = lines(StartLine)

最新更新