[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)
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.
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