我希望我的Python函数分割一个句子(输入)并将每个单词存储在一个列表中.我当前的代码拆分了句子,但没有将单词存储为列表.我怎么做?
def split_line(text):
# split the text
words = text.split()
# for each word in the line:
for word in words:
# print the word
print(words)
Run Code Online (Sandbox Code Playgroud) 什么正则表达式模式需要传递给java.lang.String.split()方法,使用所有空格字符('','\ t','\n'等)作为分隔符将String拆分为子串数组?
Java中是否有任何内置方法允许我们将逗号分隔的String转换为某个容器(例如数组,List或Vector)?或者我需要为此编写自定义代码?
String commaSeparated = "item1 , item2 , item3";
ArrayList<String> items = //method that converts above string into list??
Run Code Online (Sandbox Code Playgroud) 使用SQL Server,如何拆分字符串以便访问项目x?
拿一个字符串"Hello John Smith".如何按空格分割字符串并访问索引1处应该返回"John"的项目?
如何在JavaScript中拆分包含多个分隔符的字符串?我试图在逗号和空格上分开但是,AFAIK,JS的分割功能只支持一个分隔符.
假设我有一个Javascript数组,如下所示:
["Element 1","Element 2","Element 3",...]; // with close to a hundred elements.
Run Code Online (Sandbox Code Playgroud)
什么方法适合将数组块(拆分)到许多较小的数组中,比如最多10个元素?
我在网上找到了一些答案,但我没有使用正则表达式的经验,我认为这是我需要的.
我有一个字符串,需要用';'分割 或','也就是说,它必须是分号或逗号后跟空格.不带尾随空格的单个逗号应保持不变
示例字符串:
"b-staged divinylsiloxane-bis-benzocyclobutene [124221-30-3], mesitylene [000108-67-8]; polymerized 1,2-dihydro-2,2,4- trimethyl quinoline [026780-96-1]"
Run Code Online (Sandbox Code Playgroud)
应该拆分成包含以下内容的列表:
('b-staged divinylsiloxane-bis-benzocyclobutene [124221-30-3]' , 'mesitylene [000108-67-8]', 'polymerized 1,2-dihydro-2,2,4- trimethyl quinoline [026780-96-1]')
Run Code Online (Sandbox Code Playgroud) 我试图环顾网络寻找将字符串拆分成字符数组的答案,但我似乎无法找到一个简单的方法
str.split(//)似乎没有像Ruby那样工作.有没有循环的简单方法吗?
我正在寻找Python的等价物
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
Run Code Online (Sandbox Code Playgroud) Java有一个方便的拆分方法:
String str = "The quick brown fox";
String[] results = str.split(" ");
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法在C++中执行此操作?
split ×10
string ×5
python ×4
java ×2
javascript ×2
regex ×2
whitespace ×2
arrays ×1
c++ ×1
collections ×1
delimiter ×1
list ×1
sql ×1
sql-server ×1
t-sql ×1
tokenize ×1