strchar

strchar — Retourne le code ASCII d'un charactère dans une chaîne.

Description

Retourne le code ASCII du caractère de Sstr à la position ipos (qui vaut zéro par défaut, position du premier caractère), ou zéro si ipos est hors limites. strchar ne s'exécute que pendant l'initialisation.

Syntaxe

ichr strchar Sstr[, ipos]

Exemples

Voici un exemple de l'opcode strchar. Il utilise le fichier strchar.csd.

Exemple 844. Exemple de l'opcode strchar.

Voir les sections Audio en Temps Réel et Options de la Ligne de Commande pour plus d'information sur l'utilisation des options de la ligne de commande.

<CsoundSynthesizer>
<CsOptions>
-ndm0
</CsOptions>
<CsInstruments>
;example by joachim heintz 2013

  opcode ToAscii, S, S				;returns the ASCII numbers of the input string as string

Sin        xin 					;input string
ilen       strlen     Sin 			;its length
ipos       =          0 			;set counter to zero
Sres       =          "" 			;initialize output string
loop:                 				;for all characters in input string:
ichr       strchar    Sin, ipos 		;get its ascii code number
Snew       sprintf    "%d ", ichr 		;put this number into a new string
Sres       strcat     Sres, Snew 		;append this to the output string
           loop_lt    ipos, 1, ilen, loop 	;see comment for 'loop:'
           xout       Sres 			;return output string
  endop

  instr Characters

printf_i "\nCharacters:\n  given as single strings: %s%s%s%s%s%s\n", 1, "c", "s", "o", "u", "n", "d"
printf_i "  but can also be given as numbers: %c%c%c%c%c%c\n", 1, 99, 115, 111, 117, 110, 100 
Scsound ToAscii "csound"
printf_i "  in csound, the ASCII code of a character can be accessed with the opcode strchar.%s", 1, "\n"
printf_i "  the name 'csound' returns the numbers %s\n\n", 1, Scsound
  endin

</CsInstruments>
<CsScore>

i "Characters" 0 0
e
</CsScore>
</CsoundSynthesizer>


Voir aussi

strchark

Crédits

Auteur : Istvan Varga
2006