首页 > 文档 > split()分隔符
2017
07-21

split()分隔符

Name

split()分隔符

   

Examples

String men = “Chernenko,Andropov,Brezhnev”;

String[] list = split(men, ‘,’);

// list[0] is now “Chernenko”, list[1] is “Andropov”…

split()分隔符 - 第1张  | Processing编程艺术

String numbers = “8 67 5 309”;

int[] nums = int(split(numbers, ‘ ‘));

// nums[0] is now 8, nums[1] is now 67…

split()分隔符 - 第2张  | Processing编程艺术

String men = “Chernenko ] Andropov ] Brezhnev”;

String[] list = split(men, ” ] “);

// list[0] is now “Chernenko”, list[1] is “Andropov”…

Description

The split() function breaks a String into pieces using a character or string as the delimiter. The delim parameter specifies the character or characters that mark the boundaries between each piece. A String[] array is returned that contains each of the pieces. 

If the result is a set of numbers, you can convert the String[] array to to a float[] or int[] array using the datatype conversion functions int() and float(). (See the second example above.) 

The splitTokens() function works in a similar fashion, except that it splits using a range of characters instead of a specific character or sequence.

split () 函数使用一个字符或字符串作为分隔符将字符串分成几部分。delim 参数指定标记每个棋子之间边界的字符或字符。返回一个包含每个片断的字符串 [] 数组。

 

如果结果是一组数字, 则可以使用数据类型转换函数 int () float () 将字符串 [] 数组转换为浮点型 [] int [] 数组。(请参见上面的第二个示例。

 

splitTokens () 函数的工作方式类似, 只不过它使用一系列字符而不是特定的字符或序列进行拆分。

Syntax

split(value, delim)

Parameters

value

String: the String to be split

字符串: 要拆分的字符串

delim

char: the character or String used to separate the data

char: 用于分隔数据的字符或字符串

Returns

String[]



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

留下一个回复

你的email不会被公开。