Advertisement
Guest User

Untitled

a guest
Nov 18th, 2021
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package word.transformations;
  2.  
  3. import word.TextModifier;
  4. import word.TextTransform;
  5.  
  6. public class Cut implements TextTransform {
  7.     private String lastRemoved = "";
  8.  
  9.     @Override
  10.     public void invokeOn(TextModifier text, int startIndex, int endIndex) {
  11.         if (text.getText().toString().length() <= 0) {
  12.             return;
  13.         }
  14.         if (startIndex == endIndex) {
  15.             text.setCut("");
  16.             return;
  17.         }
  18.         this.lastRemoved = "";
  19.         for (int i = startIndex; i < endIndex; i++) {
  20.             this.lastRemoved += text.getText().charAt(i);
  21.         }
  22.         text.getText().replace(startIndex, endIndex, "");
  23.         text.setCut(lastRemoved);
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement