Creating/setting a var/Value from a single character


#1

Currently I have a monstrosity like :
StringArray alphas{ “a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n” };

thing->parameter.setValue(String(alphas[i]));

(Where “parameter” is a Value.)

I wonder if there’s any other way to do this? (Basically in this situation I need to map integers starting from 0 to alphabet characters that are used to initialize a Juce Value as a String.)


#2

I have two ideas:
a)

String alphas = "abcdefghijklmnopqrstuvwxyz";
thing->parameter.setValue (alphas.substring (i, i+1));

or b)

thing->parameter.setValue (String::charToString (i + 97));  // 97 = ascii ('a'), for upper case use 65

Hope that helps…


#3

Thanks, I had missed String::charToString… (So many functions in the String class :stuck_out_tongue: )


#4

Indeed… lot’s in there :slight_smile: