I find these particular string functions indispensable in my own web programming. I'm sure there are many other frequently-used string functions.
Action | C++ | PHP | JavaScript |
---|---|---|---|
Split a string into an array of strings | – | explode | split |
Compare strings | compare | strcmp | < or > |
Find a character within a string | find | strchr | indexOf |
Get length of string | size | strlen | length |
Find a string within a string | strstr | strstr | indexOf |
Convert a string to hexadecimal | std::hex | – | toString(16) |
Get a substring | substr | substr | substring |
Convert string to floating point | atof | floatval | parseFloat |
Convert string to integer | atoi | intval | parseInt |
Upper case first character | toupper | ucfirst | toUpperCase |
Trim white space | – | trim | trim |
Replace | replace | str_replace | replace |
Regular expression replace | c | preg_replace | replace |
Determine if string is a number | – | is_numeric | !isNan |
There are also a few useful functions that relate to single characters only, but they are usually used in the context of string processing.
Action | C++ | PHP | JavaScript |
---|---|---|---|
Get the ASCII value of a character | – | chr | fromCharCode |
Determine if character is a digit | isdigit | ctype_digit | parseInt and slice |
Determine if a character is upper case | isupper | ctype_upper | compare with toUpperCase |
No comments:
Post a Comment