dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] How can I split a string and get the value of the entire other side?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    13

    Resolved [RESOLVED] How can I split a string and get the value of the entire other side?

    I have a string in the application, the strings contents are "value1 | value2".

    I've been using this code to split it using spaces and to the 2nd so I get value 2 (that may have been worded weird sorry):
    Code:
    Dim sString As String = "value1 | value2"
    Dim split As String = sString.Split(" ")(2)
    The problem with this is, I've realized most of the value2 values will have multiple spaces and things for that side of the value. How should I go about getting the right sides contents even with multiple spaces?

    Edit: Fixed I just used sString.Split("|")(1)
    Last edited by ExoTiic; Dec 27th, 2019 at 11:08 PM.

  2. #2
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    1,009

    Re: How can I split a string and get the value of the entire other side?

    If there is always a "|" separating the values, use "|" as the Split character.

    Note: Based on your example there will be a leading space in the second value (and a trailing space in the first value for what its worth) that you will need trim off the front if that space causes you an issue.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,146

    Re: [RESOLVED] How can I split a string and get the value of the entire other side?

    Use sString.Split(New String() {“ | “}, StringSplitOptions.None)

    To get the last element, use the LINQ .Last function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width