我有一个字符串,它具有某些“标记”。
实施例:在字符串中分析并替换值可互换
"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"}
什么是做到以下几点最好的办法:我想在列表中的相应的元素来取代所有的#
字符
。
I.e.我想跳过X
和John
,并从#
和engineer
替换Jim
替换其他#
。
我以为只是循环了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"
你的问题是不可能的。如何向我们展示输入和期望的输出。 – Bohemian
@波希米亚:查看更新 – Jim