We are about to switch to a new forum software. Until then we have removed the registration on this forum.
String pi = "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170";
int x;
void draw () {
for (int i = 0; i < pi.length(); i++) {
x = int(pi.charAt(i));
println(x);
}
}
And this prints numbers around 48-58 as x in the log. I'm dumbfounded as to why it wouldn't give me the right characters from the String pi. Thank you for your help in advance.
Edit: I realized the int(pi.charAt(i))
is not working, as this results in the utf-8 character code of the given number from 0 to 9, which are 48-57. Of course, I can work around this, but would still be best to see how this should be done properly.
Answers
Yeah there are various ways to work around this.
Now what's the proper way do to it?
I don't know
I would normally use
charAt(i) - '0'
without the int() - it should already be an int. (Untested)Method CharSequence::charAt() already returns the primitive datatype
char
: ~O)Therefore, it's already "printable" as it is. B-)
Dunno why you're converting it to some other datatype! :-@
Anyways, here's my own attempt using String::toCharArray() in place of CharSequence::charAt(): O:-)
Just to make it clear CharSequence::charAt() works as well, here's my attempt using it: :bz
But the point is to get from the '3' to a 3