當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Path.Join方法代碼示例

本文整理匯總了VB.NET中System.IO.Path.Join方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Path.Join方法的具體用法?VB.NET Path.Join怎麽用?VB.NET Path.Join使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.Path的用法示例。


在下文中一共展示了Path.Join方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.IO

Module Example
    Public Sub Main()
        Dim path1 = "C:/Program Files/"
        Dim path2 = "Utilities/SystemUtilities"
        ShowPathInformation(path1, path2)

        path1 = "C:/"
        path2 = "/Program Files"
        ShowPathInformation(path1, path2)

        path1 = "C:/Users/Public/Documents/"
        path2 = "C:/Users/User1/Documents/Financial/"
        ShowPathInformation(path1, path2)
    End Sub

    Private Sub ShowPathInformation(path1 As String, path2 As String)
        Dim result = Path.Join(path1.AsSpan(), path2.AsSpan())
        Console.WriteLine($"Concatenating  '{path1}' and '{path2}'")
        Console.WriteLine($"   Path.Join:     '{result}'")
        Console.WriteLine($"   Path.Combine:  '{Path.Combine(path1, path2)}'")
        Console.WriteLine()
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.IO,代碼行數:26,代碼來源:Path.Join

輸出:

Concatenating  'C:/Program Files/' and 'Utilities/SystemUtilities'
Path.Join:     'C:/Program Files/Utilities/SystemUtilities'
Path.Combine:  'C:/Program Files/Utilities/SystemUtilities'

Concatenating  'C:/' and '/Program Files'
Path.Join:     'C:'Program Files'
Path.Combine:  '/Program Files'

Concatenating  'C:/Users/Public/Documents/' and 'C:/Users/User1/Documents/Financial/'
Path.Join:     'C:/Users/Public/Documents/C:/Users/User1/Documents/Financial/'
Path.Combine:  'C:/Users/User1/Documents/Financial/'

示例2: Program

' 導入命名空間
Imports System.IO

Module Program
    Public Sub Main()
        Dim path1 As String = "C:/"
        Dim path2 As String = "users/user1/documents"
        Dim path3 As String = "letters"
        ShowPathInformation(path1, path2, path3)
        
        path1 = "D:/"
        path2 =  "/users/user1/documents"
        path3 = "letters"
        ShowPathInformation(path1, path2, path3)

        path1 = "D:/"
        path2 =  "users/user1/documents"
        path3 = "C:/users/user1/documents/data"
        ShowPathInformation(path1, path2, path3)
    End Sub

   Private Sub ShowPathInformation(path1 As String, path2 As String, path3 As String)
        Dim result = Path.Join(path1.AsSpan(), path2.AsSpan(), path3.AsSpan())
        Console.WriteLine($"Concatenating  '{path1}, '{path2}', and `{path3}'")
        Console.WriteLine($"   Path.Join:     '{result}'")
        Console.WriteLine($"   Path.Combine:  '{Path.Combine(path1, path2, path3)}'")
    End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.IO,代碼行數:28,代碼來源:Path.Join

輸出:

Concatenating  'C:/, 'users/user1/documents', and `letters'
Path.Join:     'C:/users/user1/documents\letters'
Path.Combine:  'C:/users/user1/documents\letters'

Concatenating  'D:/, '/users/user1/documents', and `letters'
Path.Join:     'D:'users/user1/documents\letters'
Path.Combine:  '/users/user1/documents\letters'

Concatenating  'D:/, 'users/user1/documents', and `C:/users/user1/documents/data'
Path.Join:     'D:/users/user1/documents\C:/users/user1/documents/data'
Path.Combine:  'C:/users/user1/documents/data'


注:本文中的System.IO.Path.Join方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。