I am new to flutter and I just want to display a list of alphabets in a for loop. I just want to know how can I convert the integer to ascii character. I searched for this and I found dart:convert library, but I don't know how to use it.
I want something like -
for(int i=65; i<=90; i++){
print(ascii(i)); //ascii is not any method, its just to understand my question
}
It should print the letters from 'A' to 'Z'.
To convert ASCII code to a character, you can use different methods such as Type Casting, toString() method, and toChars() method of the Character class. The toString() method will return a character as a String, while the toChars() method returns the array of characters.
Use the toString() method to convert an int or double to a string. To specify the number of digits to the right of the decimal, use toStringAsFixed().
Using the chr () function, the character that represents the corresponding ASCII code can be obtained.
Here are few methods in different programming languages to print ASCII value of a given character : Python code using ord function : ord() : It converts the given string of length one, returns an integer representing the Unicode code point of the character. For example, ord('a') returns the integer 97.
You don't need dart:convert, you can just use String.fromCharCode
print(String.fromCharCode(i));
More info: https://api.dartlang.org/stable/2.0.0/dart-core/String/String.fromCharCode.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With