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

  • SEARCH
  • Home
  • 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 8927853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:18:21+00:00 2026-06-15T08:18:21+00:00

I am trying to split a string based on the – character and insert

  • 0

I am trying to split a string based on the - character and insert the words before and after the - character into a list (result) both words with different indexes. What I am trying to achieve is to check whether there is a space before and after the character -. If there is space found, perform the splitting as mentioned earlier. Otherwise, if there is no space before or after -, do not perform any splitting.

Example:

String1 = London – United Kingdom

String2 = Paris-France

Split String1 and insert London with index(0) and United Kingdom with index(1) into the result list because there is space before and after the -

Do not split String 2 and insert Paris-France with index(0)because there is no space before and after -.

Code:

        Dim result As New List(Of String)()

        For Each str_get As String In Split

            If (str_get.IndexOf("\t-\t")) Then

                Dim splitStr = str_get.Split({"-", "/"}, StringSplitOptions.None) 

                For Each str_split As String In splitStr 'Add to result list

                    result.Add(str_split.Trim()) ' Enter into result list

                    ' result.TrimExcess()
                Next

            Else


            End If

Split Is a string which may be considered as an array of strings. The For loop is to take each string in that Array and check it.

Any Thoughts or suggestions ?

  • 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-06-15T08:18:22+00:00Added an answer on June 15, 2026 at 8:18 am

    Simply try splitting on " - " instead of "-". It should work

    EDIT:

    Ok, just verified that String.Split doesn’t work that way (with a String separator)

    This will work:

    splitStr = Regex.Split(str_get, " - ")

    Demo on Ideone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to split a string into a int list for further processing. But
I'm trying to split a string into an array based on the second occurrence
I've got a string that I'm trying to split into chunks based on blank
I'm trying to split a string based on a particular character and then count
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I need to split a string into string based on the location of a
I'm trying to split the following string primarily based on whitespace. Please refer to
I am trying to use splitOn function in haskell to split a string based
I'm trying to split a string based upon the middle dot. For some reason,
I am trying to split the string in a file based on some delimiter.But

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.