How could I make this more efficient?

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
Hello Folks,

I've been trying to improve the efficiency of my giant program and I'm thankful for the help I have received here so far! I know that using a textbox to deal with a string is terribly inefficient and that's why I would be very glad if someone could provide a more efficient version of this short 8 line function.


VB.NET:
    Function CollectionSplit(ByVal TheString As String, ByVal TheSeperator As String)
        Dim tb As New TextBox
        tb.Text = TheString.Replace(TheSeperator, Environment.NewLine)
        Dim returnable As New Collection
        For Each x As String In tb.Lines
            If Not x.Length = 0 Then returnable.Add(x)
        Next
        Return returnable
    End Function

What it does is convert a string of "1,2,3" into a collection of the 3 seperate items for use later on.

Thank you.
 
VB.NET:
	Private Function CollectionSplit(ByVal TheString As String, ByVal TheSeperator As Char) As Collection
		Dim returnable As New Collection

		For Each x As String In TheString.Split(TheSeperator)
			If Not x.Length = 0 Then returnable.Add(x)
		Next

		Return returnable
	End Function

VB.NET:
Dim returned As Collection = CollectionSplit("1,2,3", ","c)

Depending what you're trying to do it may be more beneficial to create a List(Of Integer) and return that since you don't seem to need a key.
 
Back
Top