Nasal library: Difference between revisions

Jump to navigation Jump to search
→‎substr(): Add doc to do with negative integers
(→‎substr(): Add doc to do with negative integers)
Line 688: Line 688:
|syntax = substr(string, start [, length]);
|syntax = substr(string, start [, length]);
|source = {{simgear file|simgear/nasal/lib.c|l=129|t=Source}}
|source = {{simgear file|simgear/nasal/lib.c|l=129|t=Source}}
|text = Similar the {{func link|subvec}}, but operates on strings. Computes and returns a substring. The first argument specifies a string, the second is the index of the start of a substring, the optional third argument specifies a length (the default is to return the rest of the string from the start).
|text = Similar the {{func link|subvec}}, but operates on strings. Computes and returns a substring. The first argument specifies a string, the second is the index of the start of a substring, the optional third argument specifies a length (the default is to return the rest of the string from the start).
|param1 = string
|param1 = string
|param1text = String to return a substring from.
|param1text = String to return a substring from.
|param2 = start
|param2 = start
|param2text = Integer specifying the start of a substring.
|param2text = Integer specifying the start of a substring. Negative values specify a position from the end of the string.
|param3 = length
|param3 = length
|param3text = Optional argument specifying the length of the substring. Defaults to the end of the string.
|param3text = Optional argument specifying the length of the substring. Defaults to the end of the string.
|example1 = print(substr("abcde", 1, 3)); # prints "bcd"
|example1 = print(substr("abcde", 1, 3)); # prints "bcd"
|example2 = print(substr("abcde", 1)); # prints "bcde"
|example2 = print(substr("abcde", 1)); # prints "bcde"
|example3 = print(substr("abcde", 2, 1)); # prints "c"
|example3 = print(substr("abcde", 2, 1)); # prints "c"
|example4 = print(substr("abcde", -2)); # prints "de"
|example5 = print(substr("abcde", -3, 2)); # prints "cd"
}}
}}


Navigation menu