charAt method

String charAt(
  1. int index
)

Returns the character at index of the String.

Example

String foo1 = 'esentis';
String char1 = foo1.charAt(0); // returns 'e'
String char2 = foo1.charAt(4); // returns 'n'
String? char3 = foo1.charAt(-20); // returns ''
String? char4 = foo1.charAt(20); // returns ''

Implementation

String charAt(int index) {
  if (this.isBlank) {
    return this;
  }

  if (index > this.length) {
    return '';
  }
  if (index < 0) {
    return '';
  }
  return this.split('')[index];
}