[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

visual studio 2010 - reference question

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!
0
sirbounty
Asked:
sirbounty
  • 2
  • 2
1 Solution
 
choedanKalCommented:
im not sure i got you correctly, but if you start from 'H' than : Convert.ToInt32(char - 'G')
0
 
sirbountyAuthor Commented:
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$)
0
 
CodeCruiserCommented:
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.
0
 
sirbountyAuthor Commented:
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!
0
 
CodeCruiserCommented:
Glad to help. I saw 47 which was in hex column which I did not realize. H is 72.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now