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

前端 未结 7 1788
长情又很酷
长情又很酷 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:17

    I just had the same question and noticed the answer in some kind of tutorial. In general you need to use the second form of the split method, using the

    split(regex, limit)

    Here is the full tutorial http://www.rgagnon.com/javadetails/java-0438.html

    If you set some negative number for the limit parameter you will get empty strings in the array where the actual values are missing. To use this your initial string should have two copies of the delimiter i.e. you should have \t\t where the values are missing.

    Hope this helps :)

提交回复
热议问题