Extract computer name from unc path RRS feed

  • Question

  • I'm trying to figure out how to just return the computer name from eg


    ie I just want to return 


    Do I need a regular expression for this?



    Saturday, May 18, 2019 8:42 AM

All replies

  • Here is something to try without regular expressions assuming the shown is the basic format.

    Dim value = "\\" & pathValue.Split("\"c).FirstOrDefault(Function(element) Not String.IsNullOrWhiteSpace(element))

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Saturday, May 18, 2019 4:14 PM
  • You can do :

    Dim uriPath As Uri = New Uri("\\DESKTOP-1\DIRECTORY1\DIRECTORY2\......\DIRECTORYn\FILE.EXT")

    Saturday, May 18, 2019 4:24 PM