Hi All,

I'm trying to create a function to split a string by a tag - </OFX>. However, 
when trying return a seq[String], I'm getting an empty seq. I'm new to Nim, 
having primarily worked with PHP.

A couple of questions:

1\. When trying to compile without {.Discardable.} I get an error - 
van2.nim(49, 24) Error: expression 'splitstring(new_string, split_by, accu)' is 
of type 'seq[string ]' and has to be discarded; start of expression here: 
van2.nim(39, 8)

2\. Is the discardable causing the return value to be empty?

3\. How do I return a copy of the resulting sequence of string?

Thank you all!

program:
    
    
    import strutils
    import typeinfo
    import sequtils
    
    let file:string = readfile("testing")
    
    
    proc splitstring(string_to_split: string, split_by: string, acc: 
seq[string]): seq[string] {.discardable.} =
        let search_len: int = split_by.len
        let found: int = string_to_split.find(split_by)
        let end_position: int = found + search_len + -1
        echo(end_position)
        if found != -1:
            echo("string was found")
            let new_string_start: int = end_position + 1
            let new_string: string = string_to_split[new_string_start..^1]
            if len(acc) == 0:
                var accu: seq[string]
                accu.add(string_to_split[0..end_position])
                splitstring(new_string,split_by,accu)
            else:
                var accu: seq[string] = acc
                accu.add(string_to_split[0..end_position])
                splitstring(new_string,split_by,accu)
        else:
            echo(acc)
            let result = acc
            return result
    
    #start of main
    var indi_files =  splitstring(file,"</OFX>",@[])
    echo(indi_files)
    echo(indi_files)
    
    
    Run
    
    
    output:
    
    17
    string was found
    25
    string was found
    4
    @["asdfasdfasdf</OFX>", "bbbbbbbbbbbbbbbbbbbb</OFX>"]
    @[]
    @[]
    ::
    

Reply via email to