gpt4 book ai didi

java - 如何在android中替换字符串中的单词

转载 作者:行者123 更新时间:2023-11-29 21:21:57 28 4
gpt4 key购买 nike

我有一个字符串,值为 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com