code: public UTF8String subStringIndex(UTF8String delim, int count) {
      if (delim.numBytes == 0 || count == 0) {
        return EMPTY_UTF8;
      }
      if (count > 0) {
        int idx = -1;
        while (count > 0) {
          idx = find(delim, idx + 1);
          if (idx >= 0) {
            count --;
          } else {
            // can not find enough delim
            return this;
          }
        }
        if (idx == 0) {
          return EMPTY_UTF8;
        }
        byte[] bytes = new byte[idx];
        copyMemory(base, offset, bytes, BYTE_ARRAY_OFFSET, idx);
        return fromBytes(bytes);
  
      } else {
        int idx = numBytes - delim.numBytes + 1;
        count = -count;
        while (count > 0) {
          idx = rfind(delim, idx - 1);
          if (idx >= 0) {
            count --;
          } else {
            // can not find enough delim
            return this;
          }
        }
        if (idx + delim.numBytes == numBytes) {
          return EMPTY_UTF8;
        }
        int size = numBytes - delim.numBytes - idx;
        byte[] bytes = new byte[size];
        copyMemory(base, offset + idx + delim.numBytes, bytes, BYTE_ARRAY_OFFSET, size);
        return fromBytes(bytes);
      }
    }
docs: Returns the substring from string str before count occurrences of the delimiter delim.
  If count is positive, everything the left of the final delimiter (counting from left) is
  returned. If count is negative, every to the right of the final delimiter (counting from the
  right) is returned. subStringIndex performs a case-sensitive match when searching for delim.