3-9.loadTable()
Name(名称):
Examples(例子):
// The following short CSV file called “mammals.csv” is parsed
// in the code below. It must be in the project’s “data” folder.
//
// id,species,name
// 0,Capra hircus,Goat
// 1,Panthera pardus,Leopard
// 2,Equus zebra,Zebra
Table table;
void setup() {
table = loadTable(“mammals.csv”, “header”);
println(table.getRowCount() + ” total rows in table”);
for (TableRow row : table.rows()) {
int id = row.getInt(“id”);
String species = row.getString(“species”);
String name = row.getString(“name”);
println(name + ” (” + species + “) has an ID of ” + id);
}
}
// Sketch prints:
// 3 total rows in table
// Goat (Capra hircus) has an ID of 0
// Leopard (Panthera pardus) has an ID of 1
// Zebra (Equus zebra) has an ID of 2
Description(描述):Reads the contents of a file or URL and creates an Table object with its values. If a file is specified, it must be located in the sketch’s “data” folder. The filename parameter can also be a URL to a file found online. The filename must either end in an extension or an extension must be specified in the options parameter. For example, to use tab-separated data, include “tsv” in the options parameter if the filename or URL does not end in .tsv. Note: If an extension is in both places, the extension in the options is used.
读取文件或URL的内容,并使用其值创建一个Table对象。 如果指定了文件,它必须位于草图的”数据”文件夹中。 文件名参数也可以是在线查找的文件的URL。 文件名必须在扩展名中结尾,或者必须在options参数中指定扩展名。 例如,要使用制表符分隔的数据,如果文件名或URL不以.tsv结尾,则在options参数中包含”tsv”。 注意:如果两个地方都有一个分机,则使用选项中的分机。
If the file contains a header row, include “header” in the options parameter. If the file does not have a header row, then simply omit the “header” option.
如果文件包含标题行,则在options参数中包含”header”。 如果文件没有标题行,那么只需省略”标题”选项。
When specifying both a header and the file type as the options parameter, separate the options with commas, as in: loadTable(“data.csv”, “header, tsv”)
当将标题和文件类型指定为options参数时,请使用逗号分隔选项,如:loadTable(”data.csv”,”header,tsv”)
All files loaded and saved by the Processing API use UTF-8 encoding.
Processing API加载和保存的所有文件都使用UTF-8编码。
Syntax(语法):loadTable(filename)
loadTable(filename, options)
Parameters (参数):filename——name of a file in the data folder or a URL.
数据文件夹中的文件名或URL。
Options——may contain “header”, “tsv”, “csv”, or “bin” separated by commas可能包含逗号分隔的”header”,”tsv”,”csv”或”bin”
Returns(返回值):Table
Related(相关函数):Table
saveTable()
loadBytes()
loadStrings()
loadXML()
- 本文固定链接: http://iprocessing.cn/2017/07/14/loadtable读取table对象/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表