特定の「トークン」を持つ文字列があります。
例:
"Someone e.g. X here is a # and the other i.e. X is not but over is something else like #"
String のリストもあります。{"John", "doctor", "Jim","engineer"}
次のことを行う最善の方法は何ですか:すべての文字をリスト内の対応する要素に
置き換えたいです。#
つまり、スキップX
して andJohn
を置き換えたいJim
from #
and engineer
for the other #
。
をループするだけだと思っていましたstring#toCharArray()
が、これを行うためのより良い方法があるかどうかに興味がありました。
注: 2 番目のリストの値は、対応するトークンと一致します。つまり、リストの最初の値は、または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"