如何在文本视图中获取具有特定符号的特定行

How to get some specific lines in a textview that have a particular symbol

我有一个文本视图,其中有如下长文本行:

$你好我的名字是福特
我是一名电子工程师,所以等等等等等等
还有其他东西
所以其他文本....
$这是和第一行一样的另一行
等等其他普通文本

我的问题是我怎样才能只得到那些第一行上有 $ 符号的行,并只为那些特定的行设置一些效果,比如粗体和红色……而不是其他行……

有什么想法吗??!
感谢您的帮助!

编辑:
请注意,我的 textview 文本是动态的,我无法为某些特定句子编写代码。我想为每一行编写一些代码作为模板,例如以 $ 开头,加粗或类似的东西。
我也想要 $ symbole 本身;此过程后未显示在我的文本视图中!有什么想法吗?

如果您已经在 String 上有文本,您可以对 String 值使用 split 函数,然后以 html 格式显示您的行,使您能够操作大小和格式这里是一个示例:

        String stringValue="$your first line\n $your second line";
        String[] Splited=stringValue.split("$");
        //first line is in the Splited[0] and second line is in the Splited[1]
        textview.setText(Html.fromHtml("<h2>Splited[0]</h2><br><p>Spl_j[Z B1]</p>"));;

更新: 您的模板可能如下所示:

 String[] Splited=stringValue.split("\n");
 String msg="";           
    for(int i=0;i<Splited.length;i++){
       if(Splited[i].startsWith("$"))
          msg=msg+"<b>"+Splited[i]+"</b>";
       else
          msg=msg+Splited[i];

}
textview.setText(Html.fromHtml(msg));

您也可以这样做,使用搜索和替换

String yourValue="$your first line\n $your second line";
String regex = "($.*)\n";
String formattedValue = yourValue.replaceAll(regex, "<b></b>\n");
textview.setText(Html.fromHtml(formattedValue));