在 Java 中,charAt()
是一个字符串方法,用于返回指定索引处的字符。在其他编程语言中,类似的功能可能有所不同。以下是一些常见编程语言中实现类似功能的示例:
string = "hello"
index = 1
char = string[index]
print(char) # 输出: e
let string = "hello";
let index = 1;
let char = string.charAt(index);
console.log(char); // 输出: e
string str = "hello";
int index = 1;
char ch = str[index];
Console.WriteLine(ch); // 输出: e
string = "hello"
index = 1
char = string[index]
puts char # 输出: e
$string = "hello";
$index = 1;
$char = $string[$index];
echo $char; // 输出: e
请注意,这些示例中的索引都是从 0 开始的,与 Java 中的 charAt()
方法相同。