code: public void replace(int globalStartIndex, int globalEndIndex, String replacement) {
          int localStartIndex = globalIndexToLocalIndex(globalStartIndex);
          int localEndIndex = globalIndexToLocalIndex(globalEndIndex);
          String text = RunUtil.getText(run);
          text = text.substring(0, localStartIndex);
          text += replacement;
          String runText = RunUtil.getText(run);
          if (runText.length() > 0) {
              text += RunUtil.getText(run).substring(localEndIndex + 1);
          }
          RunUtil.setText(run, text);
      }
docs: Replaces the substring starting at the given index with the given replacement string.
  
  @param globalStartIndex the global index (meaning the index relative to multiple aggregated runs) at which to start the replacement.
  @param globalEndIndex   the global index (meaning the index relative to multiple aggregated runs) at which to end the replacement.
  @param replacement      the string to replace the substring at the specified global index.