我一直无法解决问题 [英] I have been unable to get a fix for a problem
问题描述
我无法解决问题。这是我的问题:
长位= 2
字符串替换= $ field2和$ field25
更换后= replacement.replace($ field+ place,'1');
当我运行它时,它会单独替换$ field2并将$ field25中的$ field2替换为1.但我想要的确切要取代的话。我怎样才能用Java实现这个目标
测试程序将是最受欢迎的。
我试过这个词边界但它不起作用
我尝试过:
我尝试过单词边界但是当我使用$ field + variable时它没有用。当我只使用$ field时它被替换了,但目的没有解决。
I have been unable to get a fix for a problem . This is my problem:
long place = 2
String replaced = $field2 and $field25
afterreplacing= replaced.replace("$field" + place, '1');
When I run this it is replacing $field2 alone and also $field2 in $field25 by 1. But I want the exact word to get replaced . How can I achieve this in Java
Tested programs will be most preferred.
I tried the word boundaries but it didn't work
What I have tried:
I tried the word boundaries but it didn't work when I used $field + variable . It was getting replaced when I was using just "$field" but the purpose is not resolved.
推荐答案
field2和
field25
afterreplacing = replacement.replace(
field25
afterreplacing= replaced.replace("
field+ place,'1');
当我运行它时正在取代
field" + place, '1');
When I run this it is replacing
这篇关于我一直无法解决问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!