Forum Discussion

lucasdeveloper's avatar
3 years ago

Split a string with 140K lines

Hello Roku Team,

I have a response HTTP that returns a txt file with 1.3MB and 140k lines.
I would like split the string in an array. I'm using the follow regex: 

text = searchRequest.getToString()
reLineSplit = CreateObject ("roRegex", "(?>\r\n|[\r\n])", "")

for each line in reLineSplit.Split (text)
end for
 
But, it's taking time to run.
Do you have a suggestion for me?

Thanks in advance.

1 Reply

  • RokuKC's avatar
    RokuKC
    Roku Employee

    That seems like an excessive amount of data to be working with. 
    Can you pass some filters to your web request to get just the data actually needed for the displayed content or business logic?
    Or use a windowed query to just download small portions of the data at a time?

    Aside from that, if you do just:

    for each line in text.Split(Chr(13) + Chr(10))
        ' do something with line
    end for

    I would expect that to be orders of magnitude faster than using roRegex.
    YMMV.