gpt4 book ai didi

dart - Dart:如何从String中获取char并进行比较

转载 作者:行者123 更新时间:2023-12-03 04:04:19 25 4
gpt4 key购买 nike

我试图从字符串中获取字符,并进行比较:

String aStr = ReadString(inputs);
String bStr = ReadString(inputs);

int diff = 0;
for (int i = 0; i < n; i++) {
if (aStr.codeUnitAt(i) != bStr.codeUnitAt(i)) {
diff++;
}
}

但是,在编译过程中出现以下错误:
Unhandled exception:
RangeError (index): Invalid value: Not in range 0..6, inclusive: 7
#0 String.codeUnitAt (dart:core-patch/string_patch.dart:927)
#1 BoomerangDecoration (file:<>/HCPast/bin/hcpast.dart:49:16)
<asynchronous suspension>
#2 main (file:<>/HCPast/bin/hcpast.dart:9:9)
<asynchronous suspension>
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)

我也尝试过charCodeAt,但据说不是String的方法。

最佳答案

经过我仔细检查后,它已经在补充 session 之后了。原因应该是超出字符串末尾的索引。

关于dart - Dart:如何从String中获取char并进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51679152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com