strncpy method

String strncpy(
  1. String dest,
  2. String src,
  3. int n
)

Copies up to n characters from the string src to dest.

If the length of src is less than n, the remainder of dest will be padded with null bytes ('\x00'). Returns the resulting string.

Implementation

String strncpy(String dest, String src, int n) {
  if (src.length >= n) {
    return src.substring(0, n);
  } else {
    return src.padRight(n, '\x00');
  }
}