Get first character of string

From LemonWiki共筆
Jump to navigation Jump to search


PHP[edit]

Using the PHP: substr function[1] Icon exclaim.gif not binary safe

echo substr('apple', 0, 1);
// return 'a'

Javascript[edit]

Using charAt() Method[2]

var str = 'apple';
var first_character = str.charAt(0);
console.log("first_character: " + first_character);

References[edit]