gpt4 book ai didi

相当于 Python 的 rsplit 的 JavaScript

转载 作者:太空狗 更新时间:2023-10-29 17:17:06 27 4
gpt4 key购买 nike

str.rsplit([sep[, maxsplit]])

Return alist of the words in the string, usingsep as the delimiter string. Ifmaxsplit is given, at most maxsplitsplits are done, the rightmost ones.If sep is not specified or None, anywhitespace string is a separator.Except for splitting from the right,rsplit() behaves like split() which isdescribed in detail below.

http://docs.python.org/library/stdtypes.html#str.rsplit

最佳答案

String.prototype.rsplit = function(sep, maxsplit) {
var split = this.split(sep);
return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
}

这个功能更接近 Python 版本

"blah,derp,blah,beep".rsplit(",",1)//['blah,derp,blah', 'beep']

关于相当于 Python 的 rsplit 的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5202085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com