我正在尝试拆分文件夹C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\Lync
中的sip_address,因为我有多个活动的SIP地址,在此示例中,我遇到了一些需要的问题,它是example2@example2.com
< / p>
此文件夹中可能还会有更多的SIP地址,但我只想有一个example2。
我从整理目录中的所有子文件夹开始,得到一个结果:
C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\Lync\sip_example1@example1.com
C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\Lync\sip_example2@example2.com
C:\Users\c%username%\AppData\Local\Microsoft\Office\16.0\Lync\Tracing
在这里,由于我的代码根本不好,因此面临分割问题,结果将是:
example2@example2.comC:\ Users \%username%\ AppData \ Local \ Microsoft \ Office \ 16.0 \ Lync \ Tracing
Imports System.IO
Public Class Form1
Dim SIPAccount As String
Private Sub GETSipAccount()
' Path and SIP-Addresses has been anonymous due to personal addresses.
For Each Dir As String In Directory.GetDirectories("C:\Users\%username%\AppData\Local\Microsoft\Office\16.0\Lync")
' List out directory
SIPAccount = SIPAccount & Dir & vbNewLine
On Error Resume Next ' I do not want to include this in my application at all
' Splits out text
SIPAccount = ((Split(Split(SIPAccount, "sip_")(1), "@example2.com")(0))) & "@example2.com"
MsgBox(SIPAccount)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GETSipAccount()
End Sub
答案 0 :(得分:0)
取决于“ example2”字符串部分对于目录地址是否唯一,您可以使用
Dim lst As List(Of String) = IO.Directory.GetDirectories("C:...").ToList
MessageBox.Show(lst.FindAll(Function(x) x.Contains("example2"))(0))
如果只想比较字符串的最后一部分,则可以使用类似的
Dim lst As List(Of String) = IO.Directory.GetDirectories("C:...").ToList
For Each item As String In lst
Dim lastindexofbackslash As Integer = item.LastIndexOf("\")
Dim _item As String = item.Substring(lastindexofbackslash + 1)
If _item.Contains("example2") Then
MsgBox(_item.Substring(4))
End If
Next