code: public UTF8String rpad(int len, UTF8String pad) {
      int spaces = len - this.numChars(); // number of char need to pad
      if (spaces <= 0 || pad.numBytes() == 0) {
        // no padding at all, return the substring of the current string
        return substring(0, len);
      } else {
        int padChars = pad.numChars();
        int count = spaces / padChars; // how many padding string needed
        // the partial string of the padding
        UTF8String remain = pad.substring(0, spaces - padChars * count);
  
        byte[] data = new byte[this.numBytes + pad.numBytes * count + remain.numBytes];
        copyMemory(this.base, this.offset, data, BYTE_ARRAY_OFFSET, this.numBytes);
        int offset = this.numBytes;
        int idx = 0;
        while (idx < count) {
          copyMemory(pad.base, pad.offset, data, BYTE_ARRAY_OFFSET + offset, pad.numBytes);
          ++ idx;
          offset += pad.numBytes;
        }
        copyMemory(remain.base, remain.offset, data, BYTE_ARRAY_OFFSET + offset, remain.numBytes);
  
        return UTF8String.fromBytes(data);
      }
    }
docs: Returns str, right-padded with pad to a length of len
  For example:
  ('hi', 5, '??') =&gt; 'hi???'
  ('hi', 1, '??') =&gt; 'h'