Page tree


Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added descriptions of string.tolower/toupper/titlecase functions, plus other improvements.

...

String functions let you manipulate strings in several ways.  They either take strings as arguments or return a string as a result (often both).  Since skin properties are always strings, and the purpose of skin expressions is usually to construct some text to display or a filename to use as a texture, these functions are the most commonly used ones.


L( id )

[Since 1.2]

This function returns the localized string whose identification number is id.  When a localized string is required by itself, this function need not be used (see first example).  However, this function allows you to combine a localized string with constant text and skin variables in order to construct a composite string (see third example).  Examples:

Code Block
languagexml
<label>135</label>
<label>#(L(135))</label>
<label>#selectedindex/#itemcount #(L(507))</label>

The first and second examples produce identical output.  Note that the first example does not use expression notation #(...), whereas the second example does use expression notation.  The third example displays a composite string in the style 8/53 items (depending on the values of the variables).  The string with id 507 must contain the localized string whose value is items.  Note though that you can achieve equivalent results using string.format().


string.contains( string a, string b )

...

Code Block
languagexml
<label>#(switch(
  eq(string.contains(#Play.Current.File,'.dvr-ms'),'true'),
    #Play.Current.File,
  eq(string.contains(#Play.Current.File,'.wtv'   ),'true'),
    #Play.Current.File,
  eq(1,1),
    #Play.Current.Title))</label>

For dvr-ms and wtv files, the built-in variable #Play.Current.Title is not set.  So this example displays the value of #Play.Current.File for dvr-ms and wtv files, and displays the value of #Play.Current.Title for all other types of file.


string.starts( string a, string b )

...

If #itemcount is 0, this function returns "no items".

If #itemcount is 1, this function returns "1 item".

If #itemcount is greater than 1, this function returns something like "53 items".


Lstring.tolower( Id string )

[Since 1.2]

This function returns the localized string for ID Id. When used alone, it is equivalent to simply using a string ID. But this function allows you to combine a localizable string with literal text and properties.  Example string converted to lower case.  Examples:

Code Block
languagexml
<label>#(string.tolower('ThIs iS A sTrInG'))</label>
<label>#(string.tolower(#TV.RecordedTV.Genre))</label>

The first example displays the text this is a string.


string.toupper( string )

This function returns string converted to upper case.  Examples:

Code Block
languagexml
<label>#selectedindex/#itemcount #(L(101<label>#(string.toupper('ThIs iS A sTrInG'))</label>
<label>#(string.toupper(#music.codec))</label>

This displays something like "8/53 items" (provided that string with id = 100 contains the localizable string "items")

Note though, that you can achieve the same results using string.format().

The first example displays the text THIS IS A STRING.


string.titlecase( string )

This function returns string converted to title case.  Title case converts the first letter of each word to upper case, and the remaining letters of each word to lower case.  Examples:

Code Block
languagexml
<label>#(string.titlecase('ThIs iS A sTrInG'))</label>
<label>#(string.titlecase(#new_file_name))</label>

The first example displays the text This Is A String.


string.ltrim( string [, charsToTrim] )

...