Hack Forums
[.NET] Spliting strings - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Spliting strings (/showthread.php?tid=4321449)



Spliting strings - Pretzels - Jul 4, 2014

Hey,

I have a richtextbox with the following content:

Code
abcd*efgh*ijkl*mnop
1234*5678*9101*1121

I have the following code to extract each line from the richtextbox:
Code
For Each file In b.Text
        Dim item As String = file.ToString
        Dim first As String() = item.split("*")(0)
        Msgbox(first)
Next

But that code, for some reason, returns only the first letter, so or a, or 1.

Why?

How else could I do this?


* - SIM-964740 - Jul 4, 2014

Code
For Each file In b.Text
      Dim item As String = file.ToString
      Dim first As String() = item.split("*")
      Dim fValue as String =  first(0)
      Dim sValue as String =  first(1)
      Msgbox(fValue)
Next

This will work and may be more useful in the future.


* - sanderele1 - Jul 4, 2014

Your problem is on this line:
PHP Code

<?php 
Dim first 
As String() = item.split("*")(0) 
Remove the () in the Dim first as string()


* - +Haze - Jul 4, 2014

I could fix the code for you, but it's better to learn for yourself.
http://howtostartprogramming.com/vb-net/vb-net-tutorial-36-splitting-strings/


* - Cairns - Jul 4, 2014

Code
For each Item as string in textbox.lines
Dim Value as string = split(item,"*")(0)
Next

Should work fine


* - Pretzels - Jul 4, 2014

Got it sorted and is now working, thanks for your help.