Tuesday, September 29, 2015

String Functions

Strings are sequences of characters. They are useful for storing data and also for accepting user input, whether it be from a terminal command line or a web form.

I find these particular string functions indispensable in my own web programming. I'm sure there are many other frequently-used string functions.

ActionC++PHPJavaScript
Split a string into an array of stringsexplodesplit
Compare stringscomparestrcmp< or >
Find a character within a stringfindstrchrindexOf
Get length of stringsizestrlenlength
Find a string within a stringstrstrstrstrindexOf
Convert a string to hexadecimalstd::hextoString(16)
Get a substringsubstrsubstrsubstring
Convert string to floating pointatoffloatvalparseFloat
Convert string to integeratoiintvalparseInt
Upper case first charactertoupperucfirsttoUpperCase
Trim white spacetrimtrim
Replacereplacestr_replacereplace
Regular expression replacecpreg_replacereplace
Determine if string is a numberis_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.

ActionC++PHPJavaScript
Get the ASCII value of a characterchrfromCharCode
Determine if character is a digitisdigitctype_digitparseInt and slice
Determine if a character is upper caseisupperctype_uppercompare with toUpperCase


No comments:

Post a Comment