visual studio 2010 - reference question

Posted on 2012-08-21
Last Modified: 2012-08-21
Within my app, I am receiving a string containing a folder path.
Within that path, there will be a number from 1 to 6 .  I have been determining the number's position by splitting the string on the "\" character - so far, it has always been in the 3rd element (though I can adjust my logic if that changes at some point).
My dilema is, I need to convert that number to a letter (1=H, 2=I, etc...6=M).
So I'd like to know what options I have to approach this.
My app needs to run a shelled process that needs the local volume, which is indicated by the numeric value in the string.
Looking for suggestions - thanks!
Question by:sirbounty

    Expert Comment

    im not sure i got you correctly, but if you start from 'H' than : Convert.ToInt32(char - 'G')
    LVL 67

    Author Comment

    Hmm - not following that route.

    Here's what I'm currently using in my function...was looking for something perhaps a bit more efficient:

      Dim ServerName As String
      Select Case FolderPath.Split("\")(3).Substring(FolderPath.Split("\")(3).Length - 2, 1)
         Case 1 ' = H
             ServerName = FolderPath.Split("\")(2).ToUpper
             FolderPath = "H:\Data" & FolderPath.Substring(FolderPath.IndexOf("\", 3)).Replace("_1$", "")

    Open in new window

    That puts FolderPath in a usuable format.  FolderPath value will be one of two path combinations, but the above works for both (i.e. something like \\server\datashare_1$\ or \\server\archiveshare_1$)
    LVL 83

    Accepted Solution

    You can try this

    Dim ServerName As String
    Dim drive As Integer = FolderPath.Split("\")(3).Substring(FolderPath.Split("\")(3).Length - 2, 1)
             ServerName = FolderPath.Split("\")(2).ToUpper
             FolderPath = chr(47+drive) & ":\Data" & FolderPath.Substring(FolderPath.IndexOf("\", 3)).Replace("_1$", "")

    H is 48 in ascii.
    LVL 67

    Author Comment

    I get where you're going with that, but ended up having to use chr(71+drive) - 47 was coming up as "/", and the resulting chr(48) was "0".
    Also modified the replace function to read in the drive variable instead of the numeric constant.

    At any rate, that should do it - thanks!
    LVL 83

    Expert Comment

    Glad to help. I saw 47 which was in hex column which I did not realize. H is 72.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now