OCaml是否具有像Python这样的String.split函数? [英] Does OCaml have String.split function like Python?
本文介绍了OCaml是否具有像Python这样的String.split函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用它来分割字符串:
I am using this to split strings:
let split = Str.split (Str.regexp_string " ") in
let tokens = split instr in
....
但是问题是,例如,这是我要解析的句子:
But the problem is that for example here is a sentence I want to parse:
pop esi
,拆分后变成(我使用辅助函数来打印tokens
列表中的每个项目):
and after the split it turns to be (I use a helper function to print each item in the tokens
list):
item: popitem: item: item: item: esi
请参阅,令牌列表中有三个空格.
See, there are three spaces in the token list.
我想知道是否有像Python这样的string.split
可以通过这种方式解析instr
:
I am wondering if there is a string.split
like in Python which can parse instr
this way:
item: popitem: esi
有可能吗?
推荐答案
不要使用Str.regexp_string
,它仅用于匹配固定字符串.
Don't use Str.regexp_string
, it's only for matching fixed strings.
使用Str.split (Str.regexp " +")
这篇关于OCaml是否具有像Python这样的String.split函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文