Kes*_*hav 10 ascii dart flutter
我是 flutter 的新手,我只想在 for 循环中显示字母列表。我只想知道如何将整数转换为 ascii 字符。我搜索了这个并找到了dart:convert库,但我不知道如何使用它。
我想要类似的东西 -
for(int i=65; i<=90; i++){
print(ascii(i)); //ascii is not any method, its just to understand my question
}
Run Code Online (Sandbox Code Playgroud)
它应该打印从“A”到“Z”的字母。
die*_*per 20
你不需要 dart:convert,你可以使用 String.fromCharCode
print(String.fromCharCode(i));
Run Code Online (Sandbox Code Playgroud)
更多信息:https : //api.dartlang.org/stable/2.0.0/dart-core/String/String.fromCharCode.html
这正是您生成字母表所需的内容:
import 'dart:core';
void RandomString() {
List<int> a = new List<int>.generate(26, (int index) => index + 65);
String f = String.fromCharCodes(a);
print(f);
}
void main() {
RandomString();
}
Run Code Online (Sandbox Code Playgroud)
您也可以在此处复制、粘贴和测试https://dartpad.dartlang.org/
在 Dart 中,使用这两个函数将 int(字节)转换为 String(字符),反之亦然。
int value = ';'.codeUnitAt(0); //get unicode for semicolon
String char = String.fromCharCode(value); //get the semicolon string ;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12509 次 |
| 最近记录: |