使用https://developer.mozilla.org/en/Java/Reference/Global_Objects/String/replace” rel=“nofollow”>.replace(
meth。 以<代码>1002取代<编码> 姓名/编码>在<代码>url下改动的<代码>1002>:
url = url.replace(/nameInstallation/g, "1002");
或者,如果您在可变的<代码>中具有替换价值,即名称:Installation = 1002:
url = url.replace(/nameInstallation/g, nameInstallation);
EDIT: As pointed out by David Thomas, you probably don t need the g
flag on the regular expression that is the first parameter to .replace()
. With this "global" flag it will replace all instances of the text "nameInstallation". Without the flag it would replace only the first instance. So either include it or leave it off according to your needs. (If you only need to replace the first occurrence you also have the option of passing a string as the first parameter rather than a regex.)