gpt4 book ai didi

java - Android 使用 indexOf

转载 作者:太空狗 更新时间:2023-10-29 15:38:35 26 4
gpt4 key购买 nike

我有这个,tweet.title 是一个字符串,等于 I love burgers.

        CharSequence i = tweet.title.indexOf(Integer.valueOf("I"));

SpannableString WordtoSpan = new SpannableString(i);
WordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

holder.txtTitle.setText(WordtoSpan);

现在我从中得到这个错误 类型不匹配:无法从 int 转换为 CharSequence

我想在字符串中找到I

最佳答案

String.indexOf 返回一个 int 而不是 CharSequence。此外,您无法使用 Integer.valueOf() 获取 I 的索引。

    int i = tweet.title.indexOf("I");

如果你只想找回“我”,这样做:

    int i = tweet.title.indexOf("I");
String s = tweet.title.substring(i, i + 1);

已编辑:我修复了这段代码中的几个错误。

关于java - Android 使用 indexOf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20164875/

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