how to cut a string by fixed length

Posted on 2006-04-17
Last Modified: 2010-04-07
I need to judge a string,
if it is longer than 10000, then the first 1-10000 will put into one string.
Then judge on the rest and if longer than 10000, repeat the same.

May I know how to do it in vb6, thanks
Question by:turbot_yu
    LVL 48

    Accepted Solution

    try something like this, i split the string and put into an array.. :

    Dim strArr() As String, bigString As String, cnt As Integer
        bigString = "Bla..... very long..."
        cnt = 0
        Do While Len(bigString) > 10000
            ReDim Preserve strArr(cnt)
            strArr(cnt) = Left$(bigString, 10000)
            bigString = Mid$(bigString, 10001)
            cnt = cnt + 1
        'Last string
        If bigString <> "" Then
            ReDim Preserve strArr(cnt)
            strArr(cnt) = bigString
        End If
    LVL 48

    Expert Comment

    by:Ryan Chong
    to get the splitted string, try something like:

    For i = 0 To UBound(strArr)
            Debug.Print strArr(i)
        Next i

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now