如何从索引0到charAt的索引中删除字符

我有一个基本的Java问题,我想得到一个答案:我需要从开始到由char确定的索引中删除String中的所有字符。

String str = "And the priest said: Come to me,you sinners"。我要将字符从“ A” 删除为“:” ,因此结果将为"Come to me,you sinners"

我尝试使用str.substring(0,str.charAt(str.indexOf(":")) str2 = str.replace(str,"") ...和其他一些变体而没有成功。整个str内容被删除,或者不起作用等。

请帮助,我知道这是一个基本问题,但我感到困惑和失败。

ykq110119 回答:如何从索引0到charAt的索引中删除字符

丢弃::v-deep;并在str.charAt之后进行选择,只需将1添加到:

indexOf
本文链接:https://www.f2er.com/3061540.html

大家都在问