【问题标题】:How to separate special string in android如何在android中分隔特殊字符串
【发布时间】:2014-07-31 11:47:15
【问题描述】:

我需要粗体和斜体在句子中特殊字符的开头(仅@,#)。

@ --> bold and italic
# --> bold 

例子:

由于光滑的@animations,Google Plus 风格的#ListViews 现在在#Android 上风靡一时。

我想要答案:

Google Plus 样式 #ListViews 近来在 #Android 上风靡一时,因为 @动画.

【问题讨论】:

  • 你有什么尝试吗?

标签: java android regex string


【解决方案1】:

String对象无法存储文本是bolditalic。它只有一个字符数组。

BoldItalic 表示视觉效果。

您可以尝试以下方法来检测应该添加效果的文本。

 String str = "Google Plus style #ListViews are all 
              the rage these days on #Android because of the slick @animations.";
 String[] arr = str.split(" ");
    for (String i : arr) {
        if (i.startsWith("#")) {
            // do something for #
        } else if(i.startsWith("@")){
            // do something for @
        } else {
           // other text 
        }
    }

【讨论】:

  • 可能startsWithcontains 更适合这里。
猜你喜欢
  • 1970-01-01
  • 2021-07-23
  • 1970-01-01
  • 1970-01-01
  • 2021-07-02
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多