Scala:删除最后一个字符 [英] Scala: Remove the last occurrence of a character
本文介绍了Scala:删除最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除字符串中最后一个字符。我可以得到索引
:
I am trying to remove the last occurrence of a character in a string. I can get its index
:
str.lastIndexOf(',')
我已经尝试使用拆分
和字符串上的替换
函数。
I have already tried to use split
and the replace
function on the string.
推荐答案
你可以用 patch
。
scala> val s = "s;dfkj;w;erw"
s: String = s;dfkj;w;erw
scala> s.patch(s.lastIndexOf(';'), "", 1)
res6: String = s;dfkj;werw
这篇关于Scala:删除最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文