1 The `trim()` function removes specific leading and trailing characters from 2 a given input string. If the characters to trim are unspecified, the space, tab, 3 carriage return and newline characters will be used by default. 4 5 Returns a copy of the input string with the specified leading and trailing 6 characters removed. 7 8 Returns `null` if the given input argment is not a valid string value. 9 10 -- Testcase -- 11 {% 12 printf("%.J\n", [ 13 // not specifying trim characters will trim whitespace 14 trim(" Hello World! \r\n"), 15 16 // if trim characters are specified, only those are removed 17 trim("|* Foo Bar +|", "+*|"), 18 19 // trim does not affect characters in the middle of the string 20 trim(" Foo Bar "), 21 trim("|Foo|Bar|", "|") 22 ]); 23 %} 24 -- End -- 25 26 -- Expect stdout -- 27 [ 28 "Hello World!", 29 " Foo Bar ", 30 "Foo Bar", 31 "Foo|Bar" 32 ] 33 -- End -- 34 35 36 Supplying an invalid string will yield `null`. 37 38 -- Testcase -- 39 {% 40 printf("%.J\n", trim(true)); 41 %} 42 -- End -- 43 44 -- Expect stdout -- 45 null 46 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt