vb.net one dimensional string array manipulation difficulty

Posted by Luay on Stack Overflow See other posts from Stack Overflow or by Luay
Published on 2010-05-14T22:33:09Z Indexed on 2010/05/14 22:54 UTC
Read the original article Hit count: 341

Filed under:
|
|

Hi,

I am having some problems with manipulating a one dimensional string array in vb.net and would like your assistance please.

My objective is to get 4 variables (if possible) from a file path. these variables are: myCountry, myCity, myStreet, Filename. All declared as string. The file location is also declared as string. so I have:

Dim filePath As String

to illustrate my problem and what I am trying to do I have the following examples:

1-

C:\my\location\is\UK\Birmingham\Summer Road\this house.txt.

In this example myCountry would be= UK. myCity= Birmingham. myStreet=Summer Road. Filename=this house.txt

2-

C:\my Location\is\France\Lyon\that house.txt.

here myCountry=France. myCity=Lyon. There is no street. Filename=that house.txt

3-

C:\my Location is\Germany\the other house.txt

Here myCountry=Germany. No city. No street. Filename=the other house.txt

What I am trying to say is I have no idea before hand about the lenght of the string or the position of the variables I want. I also don't know if I am going to find/get a city or street name in the path. However I do now that i will get myCountry and it will be one of 5 options: UK, France, Germany, Spain, Italy.

To tackle my problem, the first thing I did was

Dim pathArr() As String = filePath.Split("\")

to get the FileName I did:

FileName = pathArr.Last

To get myCountry I did:

    If filePath.Contains("UK") Then
        myCountry = "UK"
    ElseIf filePath.Contains("France") Then
        myCountry = "France"
    ElseIf filePath.Contains("Germany") Then
        myCountry = "Germany"
    ElseIf filePath.Contains("Spain") Then
        myCountry = "Spain"
    ElseIf filePath.Contains("Italy") Then
        myCountry = "Italy"
    End If

in trying to figure out myCity and myStreet (and whether they exist in the string in the first place) I started with:

Dim ind As Integer = Array.IndexOf(pathArr, myCountry)

to get the index of the myCountry string. I thought I could make my way from there but I am stuck and don't know what to do next. Any help will be appreciated.

Thanks

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about string-manipulation