首页 > 文档 > splitTokens()分隔符令牌
2017
07-21

splitTokens()分隔符令牌

Name

splitTokens()分隔符令牌

   

Examples

String t = “a b”;

String[] q = splitTokens(t);

println(q[0]); // Prints “a”

println(q[1]); // Prints “b”

splitTokens()分隔符令牌 - 第1张  | Processing编程艺术

// Despite the bad formatting, the data is parsed correctly.

// The “, ” as delimiter means to break whenever a comma *or*

// a space is found in the String. Unlike the split() function,

// multiple adjacent delimiters are treated as a single break.

String s = “a, b c ,,d “;

String[] q = splitTokens(s, “, “);

println(q.length + ” values found”); // Prints “4 values found”

println(q[0]); // Prints “a”

println(q[1]); // Prints “b”

println(q[2]); // Prints “c”

println(q[3]); // Prints “d”

Description

The splitTokens() function splits a String at one or many character delimiters or “tokens.” The delim parameter specifies the character or characters to be used as a boundary.

If no delim characters are specified, any whitespace character is used to split. Whitespace characters include tab (\t), line feed (\n), carriage return (\r), form feed (\f), and space.

After using this function to parse incoming data, it is common to convert the data from Strings to integers or floats by using the datatype conversion functions int() and float().

splitTokens () 函数将字符串拆分为一个或多个字符分隔符或令牌delim 参数指定要用作边界的字符或字符。

 

如果未指定 delim 字符, 则使用任何空白字符进行拆分。空白字符包括制表符 (\t)、行提要 (\n)、回车符 (\r)、窗体提要 (\n) 和空格。

 

使用此函数分析传入数据后, 通常可以使用数据类型转换函数 int () float () 将字符串转换为整数或浮点数。

Syntax

splitTokens(value)

splitTokens(value, delim)

Parameters

value

String: the String to be split

字符串: 要拆分的字符串

delim

String: list of individual characters that will be used as separators

字符串: 将用作分隔符的单个字符的列表

Returns

String[]

Related

split()
join()
trim()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。