字符串的字符统计

我想统计字符串中出现某个指定字符的个数,怎么统计,比如下面的:

”Aasd,LLLL,xxx“

统计逗号出现的个数

请先 登录 后评论

1 个回答

Feng Gao

DolphinDB有现成的函数:regexCount 可以统计指定字符的个数。

如:str = ”Aasd,LLLL,xxx“ ; regexCount (str, ",")

regexCount 还支持正则表达式,函数参考地址:

https://dolphindb.cn/cn/help/200/FunctionsandCommands/FunctionReferences/r/regexCount.html?highlight=reg

或者可以用,split 函数,做分割后,统计,向量的大小

split(str, ",").size() - 1


请先 登录 后评论