In this example, you can see that the string literal contains a Windows file system path. Next, the extension is extracted by invoking the Path.GetExtension method.
Finally The program shows exactly what the extension is. The period is included at the start of the three-character extension.
' Input path.
Dim p As String = "C:\Users\Sam\Documents\Test.txt"' Get extension.
Dim extension As String = Path.GetExtension(p)
' Display extension.
Console.WriteLine(".txt" = extension)
When using Path.GetExtension, developers may assume the period is not included in the extension string. We can use a string literal (like ".txt") to compare.