nirvn 0fbcc4b95d [FEATURE] upgrade the substr() function
- support negative start value (e.g. substr('hello',-2) returns 'lo')
- support negative length value (e.g. substr('hello',3,-1) returns 'll')
- length parameter now optional, defaults to end of string
  (e.g. substr('hello world',7) returns 'world')
2016-11-08 08:42:17 +10:00

17 lines
1.0 KiB
Plaintext

{
"name": "substr",
"type": "function",
"description": "Returns a part of a string.",
"arguments": [ {"arg":"string","description":"the full input string"},
{"arg":"start","description":"integer representing start position to extract from; if start is negative, the return string will begin at the end of the string minus the start value"},
{"arg":"length","optional":true,"description":"integer representing length of string to extract; if length is negative, the return string will omit the given length of characters from the end of the string"}
],
"examples": [ { "expression":"substr('HELLO WORLD',3,5)", "returns":"'LLO W'"},
{ "expression":"substr('HELLO WORLD',6)", "returns":"'WORLD'"},
{ "expression":"substr('HELLO WORLD',-5)","returns":"'WORLD'"},
{ "expression":"substr('HELLO',3,-1)", "returns":"'LL'"},
{ "expression":"substr('HELLO WORLD',-5,2)","returns":"'WO'"},
{ "expression":"substr('HELLO WORLD',-5,-1)","returns":"'WORL'"}
]
}