Eyeon:Script/Reference/Libraries/string/sub

From VFXPedia

Jump to: navigation, search

Contents

String : string.sub

Arguments

string.sub( s, start, end )

  • s (required, string)

a string to be used

  • start (required, number)

the start index of the substring, where 1 is the first character in the string

  • end (optional, number)

the end index of the substring. if no end index is provided then string.len( s ) is used (the last character in string 's')

Returns

A sub section of the string 's'

Remarks

This function extracts a piece of the string 's', between the start and end indexes. It accepts a required start index, as well as an optional end index. For example, if the function is called as string.sub(s, 1, 10) then it will return the first 10 characters in the string 's'

The third (end) argument is optional, and if it is not provided then the end of string is assumed to be the end of the substring as well.

Negative values can be used as index values, so -1 would represent the last character in the string, and -2 would represent the second last character. This can be used to reliably return suffixes and prefixes, as show in the examples below.

Requirements

  • eyeonScript 5.0
  • Fusion 5.0

Examples

-- assign a value to s s = "readme.txt" -- returns "read" x = string.sub(s, 4) print( x )


-- returns "me" x = string.sub(s, 4, 6) print( x )

-- returns the last three characters "txt" x = string.sub(s, -3) print( x )

-- returns "readme", all characters except for -- the last 4 x = string.sub(s, 1, -4) print( x)


Tips for sub (edit)

EyeonTips:Script/Reference/Libraries/string/sub