本文整理汇总了VB.NET中System.IO.Path.GetPathRoot方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Path.GetPathRoot方法的具体用法?VB.NET Path.GetPathRoot怎么用?VB.NET Path.GetPathRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Path
的用法示例。
在下文中一共展示了Path.GetPathRoot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1:
Dim pathname As String = "\mydir\"
Dim fileName As String = "myfile.ext"
Dim fullPath As String = "C:\mydir\myfile.ext"
Dim pathnameRoot As String
pathnameRoot = Path.GetPathRoot(pathname)
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", pathname, pathnameRoot)
pathnameRoot = Path.GetPathRoot(fileName)
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathnameRoot)
pathnameRoot = Path.GetPathRoot(fullPath)
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathnameRoot)
输出:
GetPathRoot('\mydir\') returns '\' GetPathRoot('myfile.ext') returns '' GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'
示例2: Module1
' 导入命名空间
Imports System.IO
Module Module1
Sub Main()
Dim P As String = "\"
Try
Console.WriteLine("Starting path: {0}", P)
Console.WriteLine("Directory name: {0}", Path.GetDirectoryName(P))
Console.WriteLine("Extension: {0}", Path.GetExtension(P))
Console.WriteLine("Filename: {0}", Path.GetFileName(P))
Console.WriteLine("Filename without extension: {0}", Path.GetFileNameWithoutExtension(P))
Console.WriteLine("Full path: {0}", Path.GetFullPath(P))
Console.WriteLine("Root: {0}", Path.GetPathRoot(P))
Catch E As Exception
Console.WriteLine("Error: {0}", E.Message)
End Try
Console.WriteLine()
End Sub
End Module