Created
May 7, 2015 14:08
-
-
Save dmelcer9/e48738b08fd784e4ca67 to your computer and use it in GitHub Desktop.
Simple substring implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simple substr implementation | |
//Paramaters | |
//String:the string you want to operate on | |
//Start:starting position, indexed from 0 | |
//End:ending position, indexed from 0 | |
//Curpos:used internally by the recursion loop- leave blank | |
//Examples | |
//echo(substr("Hello world",0,4)); Returns "Hello" | |
//echo(substr("Hello world",6,10)); Returns "world" | |
//If start/end are out of range from the string, those values will show up as undef in the resulting string | |
function substr(string,start,end,curpos=0)=(start+curpos < end)?str(string[start+curpos],substr(string,start,end,curpos+1)):string[start+curpos]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment