文本文件解析
我有许多文本文档,其中填充了 sudo 表,如下例所示。将表解析为哈希或数组之类的最佳方法是什么?
我是否编写自定义算法或者是否有现有的库?
PLACE NO. NAME DIV RANK SWIM TRANS RANK BIKE MPH TRANS RANK RUN PACE TIME
===== ===== ======================= === ==== ==== ===== ==== ======= ===== ===== ==== ====== ===== =======
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
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
===== ===== ======================= === ==== ==== ===== ==== ======= ===== ===== ==== ====== ===== =======
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想尝试
slither
You might want to try
slither
如果格式是长度固定的并且内部填充空格,那么
String#unpack
你可能会看到 http://ruby-doc.org/core/classes/String.html#M001112 了解详细信息
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