| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-ndm0 |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
;example by joachim heintz 2013 |
| 7 |
|
| 8 |
opcode ToAscii, S, S ;returns the ASCII numbers of the input string as string |
| 9 |
|
| 10 |
Sin xin ;input string |
| 11 |
ilen strlen Sin ;its length |
| 12 |
ipos = 0 ;set counter to zero |
| 13 |
Sres = "" ;initialize output string |
| 14 |
loop: ;for all characters in input string: |
| 15 |
ichr strchar Sin, ipos ;get its ascii code number |
| 16 |
Snew sprintf "%d ", ichr ;put this number into a new string |
| 17 |
Sres strcat Sres, Snew ;append this to the output string |
| 18 |
loop_lt ipos, 1, ilen, loop ;see comment for 'loop:' |
| 19 |
xout Sres ;return output string |
| 20 |
endop |
| 21 |
|
| 22 |
instr Characters |
| 23 |
|
| 24 |
printf_i "\nCharacters:\n given as single strings: %s%s%s%s%s%s\n", 1, "c", "s", "o", "u", "n", "d" |
| 25 |
printf_i " but can also be given as numbers: %c%c%c%c%c%c\n", 1, 99, 115, 111, 117, 110, 100 |
| 26 |
Scsound ToAscii "csound" |
| 27 |
printf_i " in csound, the ASCII code of a character can be accessed with the opcode strchar.%s", 1, "\n" |
| 28 |
printf_i " the name 'csound' returns the numbers %s\n\n", 1, Scsound |
| 29 |
endin |
| 30 |
|
| 31 |
</CsInstruments> |
| 32 |
<CsScore> |
| 33 |
|
| 34 |
i "Characters" 0 0 |
| 35 |
e |
| 36 |
</CsScore> |
| 37 |
</CsoundSynthesizer> |