Hello, there is a text in a variable, before displaying this text in a textview, you need to select bold text sections from ( bracket to) the bracket , and from the beginning of the text to the sign - ( dash ).
I tried this method, but I can select only a certain number of words, in this case two, and I need something specifically from the beginning of the text to - (dash). Because, in a variable, the text changes, and up to a dash there can be not two words, and not three, but more or less.
String[] tokens = e.split(" "); String twoFirstWords = tokens[0] + " " + tokens[1]; //первые два слова String content1 = e.replaceFirst(twoFirstWords, " "); //остальной текст SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableString span1 = new SpannableString(twoFirstWords); SpannableString span2 = new SpannableString(content1); span1.setSpan(new StyleSpan(Typeface.BOLD), 0, twoFirstWords.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); builder.append(span1); builder.append(span2); f2.setText(builder);