Substring: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
Created page with '{{ #vardefine:name|substring}}{{ #vardefine:return_type|string}}{{ FunctionPage| name={{#var:name}}| function_category=String Handling Routines| function1={{Function| name={{#v…'
 
imported>Bale
mNo edit summary
 
(3 intermediate revisions by one other user not shown)
Line 5: Line 5:
FunctionPage|
FunctionPage|
name={{#var:name}}|
name={{#var:name}}|
function_category=String Handling Routines|


function1={{Function|
function1={{Function|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
return_type={{#var:return_type}}|
return_also={{#var:return_also}}|
parameter1={{Param|string|full}}|
parameter2={{Param|int|start}}|
}}|
function2={{Function|
name={{#var:name}}|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
aggregate={{#var:aggregate}}|
Line 17: Line 25:
p1desc={{Pspan|full}} in the full string to extract from|
p1desc={{Pspan|full}} in the full string to extract from|
p2desc={{Pspan|start}} is the starting position|
p2desc={{Pspan|start}} is the starting position|
p2desc={{Pspan|find}} is the (optional) ending position|
p3desc={{Pspan|end}} is the (optional) ending position|
}}|
}}|


function_description=This function returns a portion of {{pspan|full}}, starting at {{pspan|start}}, and ending just before {{pspan|end}}. Note that {{pspan|end}} is optional; if omitted, the remainder of the string is returned. Both {{pspan|start}}, and optionally {{pspan|end}} are 0-indexed (but note that {{pspan|start}} is included in the returned portion, while {{pspan|end}} is not).|
function_description=This function returns a portion of {{pspan|full}}, starting at {{pspan|start}}, and ending just before {{pspan|end}}. Note that {{pspan|end}} is optional; if omitted, the remainder of the string is returned. Both {{pspan|start}}, and optionally {{pspan|end}} are 0-indexed (but note that {{pspan|start}} is included in the returned portion, while {{pspan|end}} is not). Note that if {{pspan|end}} is supplied, and greater than the length of the string (number of characters it contains), this function will abort with an "out of bounds" exception.|


code1={{CodeSample|
code1={{CodeSample|
Line 37: Line 45:
special=If {{pspan|start}} and {{pspan|end}} are equal (and in-bounds), an empty string will be returned.|
special=If {{pspan|start}} and {{pspan|end}} are equal (and in-bounds), an empty string will be returned.|
}}
}}
[[Category:String Handling Routines]]

Latest revision as of 05:10, 22 May 2010

Function Syntax

string substring(string full ,int start )

string substring(string full ,int start ,int end )

  • full in the full string to extract from
  • start is the starting position
  • end is the (optional) ending position

This function returns a portion of full, starting at start, and ending just before end. Note that end is optional; if omitted, the remainder of the string is returned. Both start, and optionally end are 0-indexed (but note that start is included in the returned portion, while end is not). Note that if end is supplied, and greater than the length of the string (number of characters it contains), this function will abort with an "out of bounds" exception.

Code Sample

Returns a portion of a string.

substring( "Some big long line of text with no real purpose." , 10 , 12);

Would result in:

Returned: on

Special

If start and end are equal (and in-bounds), an empty string will be returned.