Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetTok( string, separator, n, m = 0 ){
- //To support the old calculation, we need to do this.
- n = n - 1;
- m = m > 0 ? m : n + 1;
- local tokenized = split( string, separator ),
- text = "";
- if( n > tokenized.len() || n < 0 || m > tokenized.len() ) return null;
- tokenized = tokenized.slice( n, m );
- return tokenized.reduce( function( prev, next ){ return ( prev + separator + next ) } );
- }
- // THIS SCRIPT IS FOR TESTING THIS FUNCTION:
- local test = "I'm a quick brown little fox.";
- print( GetTok( test, " ", 1 ) );
- print( GetTok( test, " ", 1, 6 ) );
- // OUTPUT
- /*
- I'm
- I'm a quick brown little fox.
- */
Add Comment
Please, Sign In to add comment