开发者

Text file parsing

I have many text documents that are filled with sudo tables like the example below. What would be the best way to parse out the table into something like a hash or array?

Do I write a custom algorithm or are there existing libraries out there?

PLACE  NO.  NAME                    DIV    RANK  SWIM  TRANS RANK  BIKE   MPH   TRANS RANK   RUN   PACE  TIME    
===== ===== =========开发者_JAVA技巧============== ===    ====  ====  ===== ==== ======= ===== ===== ====  ====== ===== ======= 
    1     1 Krige Schabort          PCHAL    3   22:40  1:08   25 1:14:15 20.2  2:25    1   26:24  4:24 2:06:49                
    2    12 Kevin Moats             M5559   11   24:41  0:46    1 1:06:01 22.7  0:44    9   42:50  7:09 2:15:00                


You might want to try slither


if the format is length-fixed and filled with space within, what about String#unpack

you may see http://ruby-doc.org/core/classes/String.html#M001112 for details

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜