title: Android loop through string to color specific words
body: <p>I have a string that has specific words I want to color. Those words are the one's that start with #.</p>
  
  <pre><code>    if(title.contains("#")){
  
          SpannableString WordtoSpan = new SpannableString(title);   
  
          int idx = title.indexOf("#");
          if (idx &gt;= 0) {
  
              Pattern pattern = Pattern.compile("[ ,\\.\\n]");
              Matcher matcher = pattern.matcher(title);
              int wordEnd = matcher.find(idx)? matcher.start() : -1;
  
              if (wordEnd &lt; 0) {
                  wordEnd = title.length();
              }
              WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE),
                          idx,
                          wordEnd,
                          Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
          }           
  
          holder.txtTitle.setText(WordtoSpan);
      } else {
          holder.txtTitle.setText(title);
      }
  </code></pre>
  
  <p>Now lets take for example this string 
  <em>Bold part is for example the colored words.</em></p>
  
  <blockquote>
    <p>I love cheese <strong>#burgers</strong>, and with #ketchup.</p>
  </blockquote>
  
  <p>^ This is my current thing with my code. What I want is to color every <code>#</code> word, not just first one.</p>
  
  <p><strong>ex.</strong> It'll be like</p>
  
  <blockquote>
    <p>I love cheese <strong>#burgers</strong>, and with <strong>#ketchup</strong>.</p>
  </blockquote>
  
  <p>I think I need to loop? But couldn't get it clearly and working x.x</p>
  
  <hr>
  
  <p><strong>Update:</strong>
  Latest try. List becomes blank.</p>
  
  <pre><code>    SpannableString WordtoSpan = new SpannableString(title);
  
      int end = 0;
  
      Pattern pattern = Pattern.compile("[ ,\\.\\n]");
      Matcher matcher = pattern.matcher(title);
  
      int i = title.indexOf("#");
  
      for (i = 0; i &lt; title.length(); i++) {
      if (i &gt;= 0) {
  
          int wordEnd = matcher.find(i)? matcher.start() : -1;
  
          if (wordEnd &lt; 0) {
              wordEnd = title.length();
          }
          WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE),
                      i,
                      wordEnd,
                      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  
          i = end;
      }    
  
      holder.txtTitle.setText(WordtoSpan);
      }
  </code></pre>