SolvedSplitting Strings

Posts 1–8 of 8 · Page 1 of 1
Splitting Strings
I'm not all that good with working with strings such as trim and split, but I need help with this

I'm wanting to split a string into 2 separate strings that is separated with a space.

Example:
123 456
I want 123 to be its own string and 456 to be its own as well.

I would think this would work, but its not :/
Code:
Dim Data() As String = TextBox1.Text.Split(" ")
MessageBox.Show(Data(0))
Pointing me in the right direction or just giving me the code is all helpful. I'm wanting to learn how to use these functions :<
lol?

That should work.. Infact it does (just tested to be sure i am not crazy)

Data(0) will have 123
Data(1) will have 456
Should work fine. Try System.Text.RegularExpressions.Regex.Split("123 456","\s")
Lemme stop coding when I'm high.. Lemme go at this again and I'll come back if I still need help.


Edit: Got it now.
Code:
Private Sub ExperenceRank()
        Dim data() As String
        data = System.Text.RegularExpressions.Regex.Split(expAtt, "\s")
        expAtt = data(0) : rAtt = data(1)
    End Sub
Don't use RegEx for such a trivial split, it's unnecessary.

Properly, the only single-argument overload of String.Split() is String.Split(Char[]). VB lets you put a string as the argument due to it's bollocks implicit casting, but really it should be:
Code:
Private Sub ExperienceRank()
    Dim split As String() = expAtt.Split(new Char() { " "c })
    expAtt = split(0)
    rAtt = split(1) ' don't use ":", fuck me it's ugly.
End Sub
Quote Originally Posted by Broderick View Post
Don't use RegEx for such a trivial split, it's unnecessary.

Properly, the only single-argument overload of String.Split() is String.Split(Char[]). VB lets you put a string as the argument due to it's bollocks implicit casting, but really it should be:
Code:
Private Sub ExperienceRank()
    Dim split As String() = expAtt.Split(new Char() { " "c })
    expAtt = split(0)
    rAtt = split(1) ' don't use ":", fuck me it's ugly.
End Sub
Thank you.
I use ":", because it makes my code shorter
Quote Originally Posted by DawgiiStylz View Post

I use ":", because it makes my code shorter
That doesn't make your code shorter :3. It makes you have less lines, at the loss of readability. For things like variable assignment I personally wouldn't combine them into a single line using the colon.

Anyways, this is getting away from the topic.
vb.net - VB Using colons to put two statements on same line - Stack Overflow

Some reading material :3
Solved i guess
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us