我想从硬盘上的 .txt 文件中读取一串数字,将数字转换为数组中的变量,并以 .txt 文件中的数字为半径绘制圆圈。
这在处理如下代码时效果很好:
String[] numbers = loadStrings("data.txt");
radius = int(split(numbers[0], ',' ));
但是,我无法让它在 basil.js 中工作(并且已经玩了一个星期)。这是我最接近的尝试:
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
function draw() {
var linesArray = b.loadString("males.txt");
data = int(b.split(linesArray[0], ',' ));
b.ellipse(200, 200, data[0], data[0]);
}
据我所知,它无法拆分 .txt 文件中的数字并将其存储在数组中。
这是我在 stackoverflow 上的第一篇文章,请原谅我的业余!
编辑:这是txt文件的链接,我想转换成数组:http://whereverywhere.com/males.txt
最佳答案
您能否在帖子中添加外部数据文件的结构?否则很难给你具体的建议......
还有一个教程working with CSV files这几乎解释了你想要做什么......有这个例子 demos / B08_bar_chart_from_csv_data / bar_chart.jsx这也非常接近。
关于javascript - 如何将 .txt 字符串转换为 basil.js 中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20600229/