Skip to main content

String Functions

ObjectScript also provides typical string functions.

  • $Length returns the length of a string.

  • $Extract returns a substring of a string, based on a starting and ending position. You can use an asterisk (*) to represent the last character's position, and *-n to count backwards from the end.

  • $Find searches for a substring of a string, and returns the position of the character following the substring.

  • $Piece looks at a string as a series of pieces, based on a delimiter, and returns a specific piece. You can use an asterisk (*) to represent the last piece, and *-n to count pieces backwards from the end.

  • $Justify returns a string of a specified length, padded on the left with spaces (right-justified), and/or also rounds to a specified number of decimal places.

Terminal


USER>write $length("how long is this?")
17
USER>write $extract("there's gold in those hills", 9, 12)
gold
USER>write $extract("there's gold in those hills", *-4, *)
hills
USER>write $find("there's gold in those hills", "gold")
13
USER>write $piece("slice of cheese pizza", " ", 4)
pizza
USER>write $piece("slice of cheese pizza", " ", *-1)
cheese
USER>write $justify(3.1415, 10, 3)
     3.142
USER>
FeedbackOpens in a new tab