Version: v0.7.0 - Beta.  We welcome contributors & feedback.

String.setChar

setChar($index, $newChar) -> self

Description

Replace a single character at $index.

If $index is negative, it counts from the end of the string.

The index must be inside the bounds of the string.

'abcdef'.setChar(1, 'X')
//= 'Xbcdef'

'abcdef'.setChar(3, 'X')
//= 'abXdef'

'abcdef'.setChar(-1, 'X')
//= 'abcdeX'

'abcdef'.setChar(100, 'X')
//= ERROR

See Also