Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Imperceptus on May 15, 2005, 09:20 PM

Title: Split
Post by: Imperceptus on May 15, 2005, 09:20 PM
is there a way to split a string into an array based off so many bytes instead of a delimeter?
Title: Re: Split
Post by: UserLoser. on May 15, 2005, 10:18 PM

    Dim NewString$, I&
    Const AmountOfBytes& = 2
    Const TestString$ = "this is a test!"
    For I = 1 To Len(TestString) Step AmountOfBytes
        NewString = Mid$(TestString, I, AmountOfBytes)
        Debug.Print NewString
    Next I
Title: Re: Split
Post by: Grok on May 16, 2005, 12:40 PM
Quote from: Imperceptus on May 15, 2005, 09:20 PM
is there a way to split a string into an array based off so many bytes instead of a delimeter?

It's the same thing.


    Dim aNew As String()
    aNew = Split("AAA123BBB123CCC123DDD", "123")
    MsgBox aNew(2)           'shows "CCC"
Title: Re: Split
Post by: Hdx on May 16, 2005, 01:18 PM
No it's not the same thing :/ That just splits it by "123", this is what he wants:
Public Sub SplitByts(ByVal ToSplit As String, ByVal SplitBy As Integer, ByRef strOut() As String)
                   
    Dim dblSize As Double
    dblSize = Len(ToSplit) / SplitBy
    If InStr(dblSize, ".") Then dblSize = (dblSize \ 1) + 1
   
    ReDim strOut(0 To dblSize - 1)
    For x = x To dblSize - 1
        strOut(x) = Mid(ToSplit, (x * SplitBy) + 1, SplitBy)
    Next x
End Sub

It finds how big the array should be, then fills it, simple as that. The only thing that's wrong with UL's code is that it dosent add tot eh array. It splits it up fine.
~-~(HDX)~-~
Title: Re: Split
Post by: UserLoser. on May 16, 2005, 01:47 PM
Oh, oops, into an array.  Oh well, should be simple enough to modify my code to work with it..
Title: Re: Split
Post by: Imperceptus on May 21, 2005, 01:54 PM
Thanks for all your suggestions
Title: Re: Split
Post by: iNsaNe on March 05, 2006, 04:57 PM
Text1.Text = "123ABC"
Text2.text = " "

Do you mean like:

Text2.Text = Split(Text1.Text, "A")(1)

-- Then

Text2.Text = "BC"

?