CamelCase in Io

Example for versions Io-2008-01-07

This example shows char-by-char string processing. Note that at(i) returns ASCII-code of i-th character of the string, and slice(i,i+1) returns the character itself as a string of length 1. The check whether the character is a letter is done using ASCII-codes, and conversion to uppercase and string output — using string representation.

S := File standardInput readLine asLowercase;
lastSpace := 1;
for(i,0,(S size)-1,
   ascii := S at(i);
   letter := S slice(i,i+1);
   if(ascii>=97 and ascii<=122,
      if(lastSpace==1, letter := letter asUppercase);
      letter print;
      lastSpace := 0,
      lastSpace := 1;