Thank you very Mratsim! That worked. It seems like the function is returning 
too early - I'm assuming because result is being used in the if block? I 
modified the proc to make it a bit more obvious what is happening, and when. 
I'm expecting two values in the seq to be returned not one. A second question 
that I have is, I'm expecting that when proc is being called in that first if 
block - both with the if, and else that the rest of the proc is being foregone. 
Am I thinking about this the right way?
    
    
    import sequtils
    
    let file = readfile("testing")
    
    
    proc splitstring(string_to_split: string, split_by: string, acc: 
seq[string]): seq[string] {.discardable.} =
        let search_len = split_by.len
        let found = string_to_split.find(split_by)
        let end_position = found + search_len + -1
        echo(end_position)
        if found != -1:
            echo("string was found")
            let new_string_start = end_position + 1
            let new_string = string_to_split[new_string_start..^1]
            if len(acc) == 0:
                result.add(string_to_split[0..end_position])
                splitstring(new_string, split_by, result)
            else:
                result = acc
                result.add(string_to_split[0..end_position])
                splitstring(new_string,split_by, result)
        else:
            echo("the final result of splitting was ",acc)
            result = acc
    
    #start of main
    var indi_files =  splitstring(file,"</OFX>",@[])
    echo("the final result returned to indi_files ",indi_files)
    
    
    Run

Output
    
    
    17
    string was found
    25
    string was found
    4
    the final result of splitting was @["asdfasdfasdf</OFX>", 
"bbbbbbbbbbbbbbbbbbbb<                                                          
                                                                                
                                                                                
                   /OFX>"]
    the final result returned to indi_files @["asdfasdfasdf</OFX>"]
    

Reply via email to