Snippet Splitter

SerraAvenger

Cuz I can
Reaction score
234
This is similiar to Romek's exploder, just that it works for seperators of a higher length than one, too.

It is only temporarily useful until Romek fixes that issue.
needs vJASS

JASS:
library Splitter
globals
    public string array Result
    public integer Results = 0
endglobals

function StringSplit takes string toSplit, string splitter returns integer
    local integer i = 0
    local string  tmp_Split = StringCase( toSplit, false )
    
    local integer splitter_len = StringLength( splitter ) 
    
    local integer lastI = 0
    local integer nextI
    local integer maxI = StringLength( toSplit ) - splitter_len
    set splitter = StringCase( splitter, false )
    
    set Results = 0
    
    loop
        exitwhen i > maxI
        set nextI = i + splitter_len
        
        if SubString( tmp_Split, i, nextI ) == splitter then
            set Result[ Results ] = SubString( toSplit, lastI, i )
            set Results = Results + 1
            set lastI = nextI
        else
            set nextI = i + 1
        endif
        
        set i = nextI
    endloop
    
    if lastI != maxI then
        set Result[ Results ] = SubString( toSplit, lastI, StringLength( toSplit ) )
        set Results = Results + 1
    endif
    
    return Results
endfunction

endlibrary


Usage:
JASS:
local integer results = StringSplit( "abcfundeffun", "fun" ) // returns Splitter_Results.
local string array result
if results == Splitter_Results then
    call BJDebugMsg( Splitter_Result[ 0 ] ) // Displays "abc"
    //! runtextmacro PassSplitters( "result" ) // This textmacro passes all splitters into the specified string array.
    call BJDebugMsg( Splitter_Result[ 0 ] ) // Displays "(null)"
endif
 

Romek

Super Moderator
Reaction score
964
We don't need a clone of my script which 'fixes' something that isn't broken.
If you wanted it implemented, how about asking for it, instead of copying it?
I bet that never crossed your mind.

Edit: Anyway, this ones rubbish compared to my one.
 

SerraAvenger

Cuz I can
Reaction score
234
We don't need a clone of my script which 'fixes' something that isn't broken.
If you wanted it implemented, how about asking for it, instead of copying it?
I bet that never crossed your mind.

I first asked for it, then posted this snippet to help those who have the same issue.
I didn't "copy" your script, didn't even know you have one when I was programming this. Then I saw: "Oh, cool, romek has one, too!", imported it, and tested - and swoosh, it messed up the whole code by not splitting %p correctly.

I then looked into your code and saw it only worked with single char spererators, while you clearly stated otherwise in the docu. If that isn't broken, I don't know what is.

I bet you haven't even read the post.

It is only temporarily useful until Romek fixes that issue.
 

Romek

Super Moderator
Reaction score
964
> I first asked for it, then posted this snippet to help those who have the same issue.
You didn't ask for it. You posted this about 5 minutes after posting about the 'issue' in my thread.

> while you clearly stated otherwise in the docu. If that isn't broken, I don't know what is.
Bullshit. The thread clearly states that it only works for one character.

> I bet you haven't even read the post.
I did actually, and replied with that line in mind. :)

Anyway, I'll add "multiple character separators" to my one then. It seems somebody actually needed something like that. ._.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top