Estrazione di caratteri stringa
Esistono 3 metodi per estrarre i caratteri di stringa: charAt(position) charCodeAt(position) Accesso alla proprieta' [ ] Il metodo charAt() Il charAt()metodo restituisce il carattere in corrispondenza di un indice (posizione) specificato in una stringa: Esempio let text = "HELLO WORLD"; text.charAt(0) // Returns H ******************************************************** Il metodo charCodeAt() Il charCodeAt()metodo restituisce l'unicode del carattere in corrispondenza di un indice specificato in una stringa: Il metodo restituisce un codice UTF-16 (un numero intero compreso tra 0 e 65535). Esempio let text = "HELLO WORLD"; text.charCodeAt(0) // Returns 72 ************************************************ Accesso alla proprieta' ECMAScript 5 (2009) consente l'accesso alle proprieta' [ ] sulle stringhe: Esempio let text = "HELLO WORLD"; text[0] // returns H |