chrberger / stringtoolbox

A simple header-only, single-file string toolbox library for C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected output from split()

olbender opened this issue · comments

Splitting the following string
1;0;;57.71941;11.95701
gives a list of ["1", "0", "57.71941", "11.95701"]. Instead I would expect ["1", "0", "", "57.71941", "11.95701"]. This is the case for similar functions in for example Java, C#, etc.

For example:

public class Test {
     public static void main(String []args){
        String string = "1;0;;57.71941;11.95701";
        String[] parts = string.split(";");
        System.out.print("Will give '5': " + parts.length);
     }
}

A delimiter in the end or beginning of the string should also add an empty string. This can be fixed by adding an else case to both if statements where an empty string is added to the list.