String.char_at
String.char_at
功能
读取指定字符位置的字符。
语法
string.char_at(index)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| index | Int | 否 | 0 | 字符下标,负数会按 0 处理。 |
返回值
| 类型 | 说明 |
|---|---|
| String/Empty | 下标存在时返回单字符字符串;越界时返回 Empty。 |
示例
text = 'hello' result = text.char_at(1) // 输出:e print result
注意事项
- ASCII 字符串按字节下标读取;非 ASCII 字符串按 Unicode 字符下标读取。