替换字符串中的非特定子串。

问题描述 投票:-1回答:1

我想了解如何在这样的字符串中进行替换。String user ="123124.Ken:000"; 子串 .Ken:000 例如.Diana:999. 我认为,在使用 indexOf()'.' 字,但我不知道如何从该字中替换出 indexOf() 到头来 user 字符串。

java string replace substring indexof
1个回答
0
投票
id = user.split(".")[0] # this will have the value of 123124
new user = id + ".Diana:999" 

U可以写一个简单的函数,像这样。

def changeUser (oldUser, user):
    return oldUser.split('.')[0] + user

你可以使用分割函数

© www.soinside.com 2019 - 2024. All rights reserved.