我有一个具有某些“令牌”的字符串。
例子:
"Someone e.g. X here is a # and the other i.e. X is not but over is something else like #"
我还有一个字符串列表,例如{"John", "doctor", "Jim","engineer"}
执行以下操作的最佳方法是什么:
我想用列表中的相应元素替换所有字符 。#
即我想跳过X
和John
替换Jim
from#
和engineer
for the other #
。
我想只是循环,string#toCharArray()
但如果有更好的方法来做到这一点,我很感兴趣。
注意:第二个列表中的值与相应的标记匹配。因此,列表中的第一个值即John
映射到第一次出现的值X
或第#
一次出现的值。
例子:
输入: "Someone e.g. X here is a # and the other i.e. X is not but the other is something else like # but X is at least X but not #"
{"John", "doctor", "Jim","John", "engineer", "doctor"}
输出:
"Someone e.g. X here is a doctor and the other i.e. X is not but the other is something else like Jim but X is at least X but not doctor"