elisp:将文件读入列表列表 [英] elisp: read file into list of lists

查看:139
本文介绍了elisp:将文件读入列表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将文件内容读入二维列表,用换行符和空格分隔。例如,

I need to read a file contents into a two-dimensional list, split by newlines and spaces. For example,

a b
c d

需要成为

(list (list "a" "b") (list "c" "d"))

目前我只知道如何将内容读入简单列表由换行确定。每当我需要使用该列表中的一个元素时,我必须每隔一段时间分割一次空格,但是最好只能一次完成。

Currently I only know how to read the contents into a simple list determined by newlines. Whenever I need to use an element from that list, I have to split it by spaces everytime, but preferably this should be done only once beforehand.

推荐答案

像这样:

(with-current-buffer (find-file-noselect "~/foo")
  (mapcar (lambda (x) (split-string x " " t))
          (split-string
           (buffer-substring-no-properties (point-min) (point-max))
           "\n"))) 

这篇关于elisp:将文件读入列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆