0

ファイル名のないパスをピースに分割する必要があります。パスのソースは異なる OS からのものである可能性があるため、正規表現を使用するのが最善だと思います。

パスの例は次のとおりです。

     Dim _path As String = "C:\First\Second\third"
     Dim _path As String = "C:\\First\Second\third/"
     Dim _path As String = "C:/First/Second/third\"
     Dim _path As String = "C:/First\Second\third"
     Dim _path As String = "C://First/Second/third"
     Dim _path As String = "usr/bin/first/second/third"
     Dim _path As String = "/usr/bin/first/second/third/"

...および他の同様のバリエーション。

つまり、パスは "//" OR "\\" OR "/" OR "\" で分割する必要があります。

文字列配列の必要な結果は次のようになります。

    Splitted(0) = "C:"
    Splitted(1) = "First"
    Splitted(2) = "Second"
    Splitted(3) = "Third"

    OR

    Splitted(0) = "usr"
    Splitted(1) = "bin"
    Splitted(2) = "First"
    Splitted(3) = "Second"
    Splitted(4) = "Third"

これらの Regex.Split コードを VB.NET で記述する方法は?

4

1 に答える 1

2

最良かつ最速の方法は、RegExp の代わりに Split メソッドを使用することです。

Dim Splitted As String() = _path.Split(New [Char]() {"\"c, "/"c},  StringSplitOptions.RemoveEmptyEntries)
于 2013-10-31T11:22:43.087 に答える