作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个字符串,值为 hi,how r u{name};而且我还有一个大小为 3 的数组我想从字符串中找到单词“{name}”并将其替换为当前数组值 a[i]。我已经尝试过这段代码
Resources res = getResources ();
String []Questions=res. getStringArray (R.array.faq_ques);
int Questions_Array_length = Questions .length;
for(i=0; i<Questions_Array_length; i++) {
String Amith= "hi how r u {Name}";
Amith.replace("{Name}", Questions[i]);
}
最佳答案
public String replace (CharSequence target, CharSequence replacement) Added in API level 1
Copies this string replacing occurrences of the specified target sequence with another sequence. The string is processed from the beginning to the end. Parameters target the sequence to replace. replacement the replacement sequence. Returns
the resulting string.
Throws NullPointerException if target or replacement is null.
Amith = Amith.replace("{Name}", Questions[i]);
关于java - 如何在android中替换字符串中的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20632241/
我是一名优秀的程序员,十分优秀!