code: public String replaceFrom(CharSequence sequence, CharSequence replacement, CountMethod countMethod,
              SpanCondition spanCondition) {
          SpanCondition copySpan = spanCondition == SpanCondition.NOT_CONTAINED ? SpanCondition.SIMPLE
                  : SpanCondition.NOT_CONTAINED;
          final boolean remove = replacement.length() == 0;
          StringBuilder result = new StringBuilder();
          // TODO, we can optimize this to
          // avoid this allocation unless needed
  
          final int length = sequence.length();
          OutputInt spanCount = null;
          for (int endCopy = 0; endCopy != length;) {
              int endModify;
              if (countMethod == CountMethod.WHOLE_SPAN) {
                  endModify = unicodeSet.span(sequence, endCopy, spanCondition);
              } else {
                  if (spanCount == null) {
                      spanCount = new OutputInt();
                  }
                  endModify = unicodeSet.spanAndCount(sequence, endCopy, spanCondition, spanCount);
              }
              if (remove || endModify == 0) {
                  // do nothing
              } else if (countMethod == CountMethod.WHOLE_SPAN) {
                  result.append(replacement);
              } else {
                  for (int i = spanCount.value; i > 0; --i) {
                      result.append(replacement);
                  }
              }
              if (endModify == length) {
                  break;
              }
              endCopy = unicodeSet.span(sequence, endModify, copySpan);
              result.append(sequence.subSequence(endModify, endCopy));
          }
          return result.toString();
      }
docs: Replace all matching spans in sequence by replacement, according to the countMethod and spanCondition.
  The code alternates spans; see the class doc for {@link UnicodeSetSpanner} for a note about boundary conditions.
  @param sequence
  charsequence to replace matching spans in.
  @param replacement
  replacement sequence. To delete, use ""
  @param countMethod
  whether to treat an entire span as a match, or individual elements as matches
  @param spanCondition
  specify whether to modify the matching spans (CONTAINED or SIMPLE) or the non-matching
  (NOT_CONTAINED)
  @return modified string.