如何将整数的ascii值转换为flutter中的等效字符?

时间:2018-11-13 06:04:34

标签: dart flutter ascii

我是扑扑的新手,我只想在for循环中显示字母列表。我只想知道如何将整数转换为ascii字符。我进行了搜索,发现了 dart:convert 库,但我不知道如何使用它。

我想要类似-

// Create a bucket using bound parameters and put something in it.
var s3bucket = new AWS.S3();
s3bucket.createBucket(function() {
    var params = {Bucket: 'bucket/sub-bucket', Key: 'file_name1', Body: 'Hello!'};
    s3bucket.putObject(params, function(err, data) {
        if (err) {
            console.log("Error uploading data: ", err);
        } else {
            res.writeHead(200, {'Content-Type':'text/plain'});
            res.write("Successfully uploaded data to bucket/sub-bucket/");
            res.end()
        }
    });
});

它应该将字母从“ A”打印到“ Z”。

3 个答案:

答案 0 :(得分:4)

在Dart中,使用这两个函数将int(字节)转换为String(字符),反之亦然。

int value = ';'.codeUnitAt(0); //get unicode for semicolon

String char = String.fromCharCode(value); //get the semicolon string ;

答案 1 :(得分:2)

您不需要dart:convert,只需使用String.fromCharCode

 print(String.fromCharCode(i));

更多信息:https://api.dartlang.org/stable/2.0.0/dart-core/String/String.fromCharCode.html

答案 2 :(得分:0)

这恰好是您生成字母所需要的:

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();
}

您还可以在这里https://dartpad.dartlang.org/

复制,粘贴和测试它
相关问题