String parsing in Java with delimiter tab “\t” using split

前端 未结 7 1745
长情又很酷
长情又很酷 2020-11-27 06:01

I\'m processing a string which is tab delimited. I\'m accomplishing this using the split function, and it works in most situations. The problem occurs when a f

7条回答
  •  孤城傲影
    2020-11-27 06:21

    String[] columnDetail = new String[11];
    columnDetail = column.split("\t", -1); // unlimited
    OR
    columnDetail = column.split("\t", 11); // if you are sure about limit.
    
     * The {@code limit} parameter controls the number of times the
     * pattern is applied and therefore affects the length of the resulting
     * array.  If the limit n is greater than zero then the pattern
     * will be applied at most n - 1 times, the array's
     * length will be no greater than n, and the array's last entry
     * will contain all input beyond the last matched delimiter.  If n
     * is non-positive then the pattern will be applied as many times as
     * possible and the array can have any length.  If n is zero then
     * the pattern will be applied as many times as possible, the array can
     * have any length, and trailing empty strings will be discarded.
    

提交回复
热议问题