Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 792215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:57:28+00:00 2026-05-14T21:57:28+00:00

I am having some problems with manipulating a one dimensional string array in VB.NET

  • 0

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 beforehand about the length 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 know 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:57:28+00:00Added an answer on May 14, 2026 at 9:57 pm

    Using pathArr was a good idea already. You can use an index variable to loop through the components. The following code is untested but should get you started:

    Dim countries As New String() {"UK", "France", "Germany", "Spain", "Italy"}
    
    Dim pathArr() As String = filePath.Split("\")               ' " <-- this is just to fix SO syntax highlighting
    
    ' Find the component containing the country '
    Dim i = 0
    Do Until i >= pathArr.Length OrElse countries.Contains(pathArr(i))
        i += 1
    Loop
    
    If i >= pathArr.Length - 1 Then
        ... ' Error: No Country found or Country is last component'
    Else
        myCountry = pathArr(i)
        i += 1
        If i < pathArr.Length - 1 Then
            myCity = pathArr(i)
            i += 1
            If i < pathArr.Length - 1 Then
                myStreet = pathArr(i)
                i += 1
                If i < pathArr.Length - 1 Then
                    ... ' Error: Too many components '
                End If
            End If
        End If
        FileName = pathArr(i)
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 429k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I try the next code with your proxylist but it… May 15, 2026 at 1:44 pm
  • Editorial Team
    Editorial Team added an answer Artefacto made me look at the output with more attention… May 15, 2026 at 1:44 pm
  • Editorial Team
    Editorial Team added an answer This is admittedly a very basic level quiz, but you… May 15, 2026 at 1:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.