String.split()分割字符串

string.split(s[, sep[, maxsplit]])

Return a list of the words of the string s. If the optional second argument sep is absent or None, the words are separated by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed). If the second argument sep is present and not None, it specifies a string to be used as the word separator. The returned list will then have one more item than the number of non-overlapping occurrences of the separator in the string. If maxsplit is given, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).

The behavior of split on an empty string depends on the value of sep. If sep is not specified, or specified as None, the result will be an empty list. If sep is specified as any string, the result will be a list containing one element which is an empty string.

时间: 2024-11-05 02:47:36

String.split()分割字符串的相关文章

C#的String.Split 分割字符串用法详解的代码

代码期间,把代码过程经常用的内容做个珍藏,下边代码是关于C#的String.Split 分割字符串用法详解的代码,应该对码农们有些用途. 1) public string[] Split(params char[] separator)2) public string[] Split(char[] separator, int count)3) public string[] Split(char[] separator, StringSplitOptions options)4) public

java关于split分割字符串,空的字符串不能得到的问题

java关于split分割字符串,空的字符串不能得到的问题 class T { public static void main(String args[]) { String num[] = new String[11]; String sLine = "101494|360103660318444|2008/06/17|周润英|1292.0|3085.76|2778.28|912.91|106.0|||"; num = sLine.split("\\|"); in

java split 分割字符串用法

在java.lang包中有String.split()方法,返回是一个数组.   1.“.”和“|”都是转义字符,必须得加"\\"; 如果用“.”作为分隔的话,必须是如下写法:String.split("\\."),这样才能正确的分隔开,不能用String.split(".");如果用“|”作为分隔的话,必须是如下写法:String.split("\\|"),这样才能正确的分隔开,不能用String.split("|

String split 分隔字符串,多个分隔符、正则表达式学习示例

import java.util.Arrays; import org.junit.Test; /** * 通过几个例子学习String split方法 * 尤其是记住使用多个分隔符的方式 * @author lzg * */ public class StringSplitTest { /** * 待分隔的字符串全是由分隔符组成 */ @Test public void test1(){ String str = ",,,,,,"; String [] strArray = str.

【lua】lua string.match 和 string.split 从字符串中寻找特定字符串并保存

local string = "{1,2,3,4}" local traString=string.match(string , "%d+,%d+,%d+,%d+") --此时tranString = "1,2,3,4",去掉"{","}" string = string.split(tranString , ",") string = {1,2,3,4} string[1]=1 str

java类中与js中split分割字符串转数组区别

java类中,以","分割,将字符串转化为数组 String str = "a,b,c,"; String[] arr = str.split(","); System.out.println(arr.length); 输出长度为3,arr[0]="a"; arr[1]="b"; arr[2]="c"; js中,以","分割,将字符串转化为数组 var str = &

C#的split()分割字符串

简单的说: 在C#中 str.Split("===="); //这样是错误的,只能 str.Split('=');//参数只能是char类型的,不能是字符串的 如果非得要以字符串分割,那么请用: string content = "I love you=====do you know===shit"; string[] sArray = null; sArray = System.Text.RegularExpressions.Regex.Split(content

C++ split分割字符串函数

将字符串绑定到输入流istringstream,然后使用getline的第三个参数,自定义使用什么符号进行分割就可以了. #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; void split(const string& s,vector<int>& sv,const char flag =

js split 的用法和定义 js split分割字符串成数组的实例代码

<script language="javascript"> str="2,2,3,5,6,6"; //这是一字符串 var strs= new Array(); //定义一数组 strs=str.split(","); //字符分割 for (i=0;i<strs.length ;i++ ) { document.write(strs[i]+"<br/>"); //分割后的字符输出 } <