Created
March 1, 2025 20:38
-
-
Save slightfoot/7cff68d2f367c6c33e92ae8b2c7f4f57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String intToString(int value) { | |
final chars = <int>[]; | |
while (value > 0) { | |
// 0x30 == ASCII '0' | |
chars.add(0x30 + (value % 10)); | |
value ~/= 10; | |
} | |
return String.fromCharCodes(chars.reversed); | |
} | |
void main() { | |
final n = 123456; | |
print(intToString(n)); | |
print('$n'); | |
// this is same as print('$n'); | |
final _hiddenBuffer1 = StringBuffer(); | |
_hiddenBuffer1.write(n.toString()); | |
print(_hiddenBuffer1.toString()); | |
// this is same as print('$n') but less steps | |
print(n.toString()); | |
print('value is $n pixels'); | |
final _hiddenBuffer2 = StringBuffer(); | |
_hiddenBuffer2.write('value is '); | |
_hiddenBuffer2.write(n.toString()); | |
_hiddenBuffer2.write(' pixels'); | |
print(_hiddenBuffer2.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment