Get first character of string: Difference between revisions
Jump to navigation
Jump to search
(Created page with " == PHP == Using the [https://www.php.net/manual/en/function.substr.php PHP: substr] function<ref>[https://www.php.net/manual/en/function.substr.php PHP: substr - Manual]</re...") |
(No difference)
|
Revision as of 18:14, 23 October 2020
PHP
Using the PHP: substr function[1]
not binary safe
echo substr('apple', 0, 1);
// return 'a'
Javascript
Using charAt() Method[2]
var str = 'apple';
var first_character = str.charAt(0);
console.log("first_character: " + first_character);