Player APIs (BrightScript & Ja...
...
Object Reference
BrightScript Core Objects

roInt, roFloat, roString

21min
the variables, literals, and types docid 5b4v8u6r1zwdk71zygdc5 int32 , float , and string have object and interface equivalents these are useful in the following situations an object is needed instead of a typed value (e g the rolist object maintains a list of objects) when a function that expects a brightscript object as a parameter is passed an integer, float, or string, brightscript automatically creates the equivalent object if any object exposes the ifint , iffloat , or ifstring interfaces, that object can be used in any expression that expects a typed value for example, an docid\ g1zemm qk7fbcyniuk6fi can be used as an integer with a value representing the event id integer operations if "o" is of type roint , then these statements will have the following effects print o prints the value of o getint() i%=o assigns the integer i% the value of o getint() k=o presumably k is automatically typed, so it becomes another reference to the roint o o=5 this is not the same as o setint(5) instead it releases o , changes the type of o to roint32 ( o is automatically typed), and assigns it to 5 ifint roint contains the ifint interface, which provides the following getint() as integer returns the integer value of the object setint(value as integer) as void sets the integer value of the object ifintops roint also contains the ifintops interface, which provides the following tostr() as string returns the integer value as a string a space is not appended to the front for positive numbers iffloat rofloat contains the iffloat interface, which provides the following getfloat() as float returns the float value of the object setfloat(value as float) as void sets the float value of the object ifstring rostring contains the ifstring interface, which provides the following getstring() as string returns the string value of the object setstring(value as string) as void sets the string value of the object ifstringops rostring also contains the ifstringops interface, which provides the following some global functions docid\ nsjxffr7olfgdwgjfebme offer the same functionality as ifstringops methods the function indexes of ifstringops methods start at zero, while those of global functions start at one setstring(str as string, str len as integer) sets the string value of the object using the specified string and string length values this is similar to the setseting() method, which does not accept a parameter for string length appendstring(str as string, str len as integer) appends to the string value of the object using the specified string and string length values this method modifies itself—this can cause unexpected results when you pass an intrinsic string type, rather than a string object example x="string" x ifstringops appendstring("ddd",3) print x 'will print 'string' y=box("string") y ifstringops appendstring("ddd",3) print y 'will print 'stringddd' len() as integer returns the number of characters in a string getentityencode() as string returns the string with certain characters replaced with html entity encoding sequences character replaced with " (double quote) " ' (single quote) ' < < > > & & tokenize(delim as string) as rolist splits a string into substrings using the specified delimiter character(s) the delim parameter can contain one or more characters to treat as delimiters if the string object contains multiple contiguous delimiters, they will be treated as a single delimiter this method returns the substrings as an rolist object; the delimiters are not returned with the substrings example brightscript> s = "one&\&two" brightscript> print s tokenize("&") one two trim() as string returns the string with any leading and trailing whitespace characters (e g tab, lf, cr, vt, ff, no break space) removed toint() as integer returns the value of the string as an integer number tofloat() as float returns the value of the string as a floating point number left(n as integer) as string returns the first n characters of the string right(n as integer) as string returns the last n characters of the string mid(start index as integer) as string returns a subset of the string that begins at the zero based start index and terminates at the end of the string mid(start index as integer, n as integer) as string returns a subset of the string, beginning at the zero based start index and consisting of n characters if the string contains fewer than n characters after the specified start index , this method will return all characters after the start index instr(substring as string) as integer returns the zero based index of the first occurence of the substring in the string if the substring does not occur in the string, this method returns 1 instr(start index as integer, substring as string) as integer returns the zero based index of the first occurence of the substring after the specified start index in the string if the substring does not occur after the specified start index , this method returns 1 instr() is also offered as a global functions docid\ nsjxffr7olfgdwgjfebme (note that the string index of the global function starts at 1) examples brightscript> o=createobject("roint") brightscript> o setint(555) brightscript> print o 555 brightscript> print o getint() 555 brightscript> print o 55 500 an integer value of 5 is converted to type roint automatically because the addtail() method expects a brightscript object as its parameter brightscript> list=createobject("rolist") brightscript> list addtail(5) brightscript> print type(list gettail()) here the listdir() method returns an rolist object containing rostring objects brightscript> l=listdir("/") brightscript> for i=1 to l count()\ print l removehead()\ next test movie 3 vob test movie 4 vob test movie 1 vob test movie 2 vob