String Manipulation Functions: Difference between revisions
(30 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
The [[#Clean|Clean()]] function is generally used to sanitize a <i>string</i> by stripping empty brackets, remove superfluous dash characters, eliminate leading or trailing articles, or replace filesystem-illegal characters. It is typically employed before some operation such as Rename to clean the product of joining various fields, some of which may be empty, or to produce filesystem-safe filenames. It may be used for a variety of purposes, however. |
The [[#Clean|Clean()]] function is generally used to sanitize a <i>string</i> by stripping empty brackets, remove superfluous dash characters, eliminate leading or trailing articles, or replace filesystem-illegal characters. It is typically employed before some operation such as Rename to clean the product of joining various fields, some of which may be empty, or to produce filesystem-safe filenames. It may be used for a variety of purposes, however. |
||
{{argument table |
{{argument table |
||
| name= |
| name=mode |
||
| contents= |
| contents= |
||
{{argument table row|0|Removes empty () and [], superfluous dash (-) and whitespace characters and sometimes comma (be careful).}} |
{{argument table row|0|Removes empty () and [], superfluous dash (-) and whitespace characters and sometimes comma (be careful).}} |
||
Line 34: | Line 34: | ||
: Changes the case of a given string. |
: Changes the case of a given string. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=FixCase |
||
| arguments=string, mode |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>fixcase(</b><i>string</i><b>, </b><i>mode</i><b>)</b></span> |
|||
{{argument optional}} |
|||
The [[#FixCase|FixCase()]] function will convert the supplied text <i>string</i> according to the specified <i>mode</i>. |
The [[#FixCase|FixCase()]] function will convert the supplied text <i>string</i> according to the specified <i>mode</i>. |
||
{{argument table |
|||
| name=mode |
|||
Available <i>mode</i> values: |
|||
| contents= |
|||
{{argument table row|0|Title Case}} |
|||
<div style="margin-left: 20pt;"><table style="border-spacing:0px; border-collapse:collapse; background: #f9f9f9"> |
|||
{{argument table row|1|All words}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>0</b></td><td>Title Case</td></tr> |
|||
{{argument table row|2|First word}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>1</b></td><td>All Words</td></tr> |
|||
{{argument table row|3|All uppercase}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>2</b></td><td>First Word</td></tr> |
|||
{{argument table row|4|All lowercase}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>3</b></td><td>All Uppercase</td></tr> |
|||
{{argument table row|5|All words (preserve existing capitalization)}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>4</b></td><td>All Lowercase</td></tr> |
|||
}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>5</b></td><td>All Words (preserve existing capitalization)</td></tr> |
|||
| examples= |
|||
</table></div> |
|||
'''{{monospace|<nowiki>fixcase(enjoy the silence)</nowiki>}}''' |
|||
: The default <i>mode</i> 0 is used, so the output is: <span style="font-family: monospace,monospace; font-size:1em;">Enjoy the Silence</span>. |
|||
Argument <i>mode</i> is optional (defaults to 0). |
|||
'''{{monospace|<nowiki>fixcase(enjoy the silence, 1)</nowiki>}}''' |
|||
: Using <i>mode</i> 1, all words are uppercased, so the output is: <span style="font-family: monospace,monospace; font-size:1em;">Enjoy The Silence</span>. |
|||
|- valign="top" |
|||
'''{{monospace|<nowiki>fixcase(MY ALbUm IS cAlLeD: adam, 4)</nowiki>}}''' |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
: Outputs: <span style="font-family: monospace,monospace; font-size:1em;">my album is called: adam</span>. |
|||
'''{{monospace|<nowiki>fixcase(MY ALbUm IS cAlLeD: adam, 5)</nowiki>}}''' |
|||
<p style="margin-left:20pt;">The default <i>mode</i> 0 is used, so the output is <span style="font-family: monospace,monospace; font-size:1em;">Enjoy the Silence</span>.</p> |
|||
: Using ''mode'' 5, the initial character of each word is uppercased, but other existing capitalization is preserved, so the output is: {{monospace|MY ALbUm IS CAlLeD: Adam}}. |
|||
<span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>fixcase(enjoy the silence, 1)</nowiki></b></span> |
|||
}} |
|||
<p style="margin-left:20pt;">Using <i>mode</i> 1, all words are uppercased, so the output is <span style="font-family: monospace,monospace; font-size:1em;">Enjoy The Silence</span>.</p> |
|||
<span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>fixcase(MY ALbUm IS cAlLeD: adam, 4)</nowiki></b></span> |
|||
<p style="margin-left:20pt;">Outputs <span style="font-family: monospace,monospace; font-size:1em;">my album is called: adam</span>.</p> |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="FixSpacing">FixSpacing(…)</span> === |
=== <span id="FixSpacing">FixSpacing(…)</span> === |
||
: Intelligently splits adjacent camel-cased words. |
: Intelligently splits adjacent camel-cased words. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=FixSpacing |
||
| arguments=string, mode |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>fixspacing(</b><i>string</i><b>, </b><i>mode</i><b>)</b></span> |
|||
{{argument optional|mode|1}} |
|||
The [[#FixSpacing|FixSpacing()]] function inserts spaces between adjacent camel-cased words in <i>string</i>. |
|||
It is useful for helping to clean and convert metadata that favors compactness over standard sentence structure. |
The [[#FixSpacing|FixSpacing()]] function inserts spaces between adjacent camel-cased words in <i>string</i>. It is useful for helping to clean and convert metadata that favors compactness over standard sentence structure. |
||
{{argument table |
|||
| name=mode |
|||
Available <i>mode</i> values: |
|||
| contents= |
|||
{{argument table row|0|Disables conversion}} |
|||
<div style="margin-left: 20pt;"><table style="border-spacing:0px; border-collapse:collapse; background: #f9f9f9"> |
|||
{{argument table row|1|Enables camel-case conversion}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>0</b></td><td>Disables conversion</td></tr> |
|||
}} |
|||
<tr><td style="text-align:left; padding-right:20pt"><b>1</b></td><td>Enables camel-case conversion</td></tr> |
|||
| examples= |
|||
</table></div> |
|||
'''{{monospace|<nowiki>fixspacing(OneWorld)</nowiki>}}''' |
|||
: Outputs <span style="font-family: monospace,monospace; font-size:1em;">One World</span>. |
|||
Argument <i>mode</i> is optional (defaults to 1). |
|||
'''{{monospace|<nowiki>fixspacing([name], 1)</nowiki>}}''' |
|||
: Outputs the name field with any camel-case converted into standard sentence structure. If the value of name was, <span style="font-family: monospace,monospace; font-size:1em;">MiracleOn34thStreet</span>, the output would be <span style="font-family: monospace,monospace; font-size:1em;">Miracle On 34th Street</span>. |
|||
|- valign="top" |
|||
'''{{monospace|<nowiki>fixspacing(Another [name])</nowiki>}}''' |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
: Assuming the same [name] as above, this would return <span style="font-family: monospace,monospace; font-size:1em;">Another Miracle On 34th Street</span>. |
|||
}} |
|||
<p style="margin-left:20pt;">Outputs <span style="font-family: monospace,monospace; font-size:1em;">One World</span>.</p> |
|||
<span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>fixspacing([name], 1)</nowiki></b></span> |
|||
<p style="margin-left:20pt;">Outputs the name field with any camel-case converted into standard sentence structure. |
|||
If the value of name was, <span style="font-family: monospace,monospace; font-size:1em;">MiracleOn34thStreet</span>, the output would be <span style="font-family: monospace,monospace; font-size:1em;">Miracle On 34th Street</span>.</p> |
|||
<span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>fixspacing(Another [name])</nowiki></b></span> |
|||
<p style="margin-left:20pt;">Assuming the same [name] as above, this would return <span style="font-family: monospace,monospace; font-size:1em;">Another Miracle On 34th Street</span>.</p> |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="Hexify">Hexify(…)</span> === |
=== <span id="Hexify">Hexify(…)</span> === |
||
: Hexifies a string to make it suitable for web usage. |
: Hexifies a string to make it suitable for web usage. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=Hexify |
||
| arguments=string |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>hexify(</b><i>string</i><b>)</b></span> |
|||
The [[#Hexify|Hexify()]] function URI encodes a <i>string</i> to make it useable by a browser or search engine. |
The [[#Hexify|Hexify()]] function URI encodes a <i>string</i> to make it useable by a browser or search engine. [[#Hexify|Hexify()]] is typically used by expressions generating or working on URLs in Media Center's [[Link Manager]]. |
||
| examples= |
|||
[[#Hexify|Hexify()]] is typically used by expressions generating or working on URLs in Media Center's Link Manager. |
|||
'''{{monospace|<nowiki>hexify(Oasis - /(What's The Story/) Morning Glory?)</nowiki>}}''' |
|||
|- valign="top" |
|||
: The result is <span style="font-family: monospace,monospace; font-size:1em;">Oasis%20-%20%28What%27s%20The%20Story%29%20Morning%20Glory%3F</span>. |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
}} |
|||
|style="background: #f9f9f9; color: #111; border-style: solid; border-width: 0px 2px 2px 0; border-top: 1px solid #bbb;" | <span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>hexify(Oasis - /(What's The Story/) Morning Glory?)</nowiki></b></span> |
|||
<p style="margin-left:20pt;">The result is <span style="font-family: monospace,monospace; font-size:1em;">Oasis%20-%20%28What%27s%20The%20Story%29%20Morning%20Glory%3F</span>.</p> |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="Left">Left(…)</span> === |
=== <span id="Left">Left(…)</span> === |
||
: Retrieves a specified number of characters from the left of a string. |
: Retrieves a specified number of characters from the left of a string. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=Left |
||
| arguments=string, quantity |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>left(</b><i>string</i><b>, </b><i>quantity</i><b>)</b></span> |
|||
The [[#Left|Left()]] function retrieves no more than <i>quantity</i> characters from the left of the <i>string</i>. |
The [[#Left|Left()]] function retrieves no more than <i>quantity</i> characters from the left of the <i>string</i>. |
||
| examples= |
|||
|- valign="top" |
|||
'''{{monospace|<nowiki>left([filename], 3)</nowiki>}}''' |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
: Return the Windows drive letter, colon and first back-slash from the filename (for filenames beginning with a windows drive letter). |
|||
|style="background: #f9f9f9; color: #111; border-style: solid; border-width: 0px 2px 2px 0; border-top: 1px solid #bbb;" | <span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>left([filename], 3)</nowiki></b></span> |
|||
}} |
|||
<p style="margin-left:20pt;">Return the Windows drive letter, colon and first back-slash from the filename.</p> |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="Length">Length(…)</span> === |
=== <span id="Length">Length(…)</span> === |
||
: Returns the number of characters in a string. |
: Returns the number of characters in a string. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=Length |
||
| arguments=string |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>length(</b><i>string</i><b>)</b></span> |
|||
The [[#Length|Length()]] function returns the number of characters contained in <i>string</i>. |
The [[#Length|Length()]] function returns the number of characters contained in <i>string</i>. |
||
| examples= |
|||
|- valign="top" |
|||
'''{{monospace|<nowiki>length(A Simple Plan)</nowiki>}}''' |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
: Returns 13. |
|||
|style="background: #f9f9f9; color: #111; border-style: solid; border-width: 0px 2px 2px 0; border-top: 1px solid #bbb;" | <span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>length(A Simple Plan)</nowiki></b></span> |
|||
'''{{monospace|<nowiki>if(compare(length([filename]), >=, 68), Long, Short)</nowiki>}}''' |
|||
<p style="margin-left:20pt;">Returns 13.</p> |
|||
<span style="font-family: monospace,monospace; font-size:1em;">< |
: The length of the filename is calculated, and compared against 68, outputting <span style="font-family: monospace,monospace; font-size:1em;">Long</span> when the length is greater than or equal to 68, and <span style="font-family: monospace,monospace; font-size:1em;">Short</span> otherwise. |
||
}} |
|||
<p style="margin-left:20pt;">The length of the filename is calculated, and compared against 68, outputting <span style="font-family: monospace,monospace; font-size:1em;">Long</span> when the length is greater than or equal to 68, and <span style="font-family: monospace,monospace; font-size:1em;">Short</span> otherwise.</p> |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="Mid">Mid(…)</span> === |
=== <span id="Mid">Mid(…)</span> === |
||
: Retrieves specified characters from a string. |
: Retrieves specified characters from a string. |
||
{{function description box |
|||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
|||
| |
| name=Mid |
||
| arguments=string, start position, quantity |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 2px 1px 0 2px; border-right: 1px solid #bbb;" width="100" | Description |
|||
| description= |
|||
| style="background: #f9f9f9; color: #111; border-style: solid; border-width: 2px 2px 0 0" width="1200" | <span style="font-family: monospace,monospace; font-size:1em; color:#0f3f8d; font-size:110%"><b>mid(</b><i>string</i><b>, </b><i>start position</i><b>, </b><i>quantity</i><b>)</b></span> |
|||
{{argument optional|start position|0}} |
|||
{{argument optional|quantity|1}} |
|||
The [[#Mid|Mid()]] function returns a specified <i>quantity</i> of characters from the <i>start position</i> in <i>string</i>. |
The [[#Mid|Mid()]] function returns a specified <i>quantity</i> of characters from the <i>start position</i> in <i>string</i>. |
||
The <i>start position</i> is 0-based (i.e. the first character is considered position 0). |
The <i>start position</i> is 0-based (i.e. the first character is considered position 0). A quantify of -1 returns all characters from the start positionning to the end of <i>string</i>. |
||
| examples= |
|||
A quantify of -1 returns all characters from the start positionning to the end of <i>string</i>. |
|||
'''{{monospace|<nowiki>mid(12345)</nowiki>}}''' |
|||
: Returns <span style="font-family: monospace,monospace; font-size:1em;">1</span>, using is the default <i>quantity</i> (1) of characters from the default <i>start position</i> of (0 - the beginning of the <i>string</i>). |
|||
Argument <i>start position</i> is optional (defaults to 0). |
|||
'''{{monospace|<nowiki>mid(12345, 1, 2)</nowiki>}}''' |
|||
: Returns 2 characters beginning at <i>start position</i> 1, which is <span style="font-family: monospace,monospace; font-size:1em;">23</span>. |
|||
Argument <i>quantity</i> is optional (defaults to 1). |
|||
'''Additional Examples:''' |
|||
* [http://yabb.jriver.com/interact/index.php?topic=52809.0 An example that uses Mid() to re-order a date field.] |
|||
|- valign="top" |
|||
* [http://yabb.jriver.com/interact/index.php?topic=75891.0 An example that uses Mid() to output a number of stars based on an arbitrary rating value.] |
|||
! scope="row" style="background: #ecedf3; color: #111; border-style: solid; border-width: 0px 1px 2px 2px; border-top: 1px solid #bbb; border-right: 1px solid #bbb;" | Examples |
|||
}} |
|||
|style="background: #f9f9f9; color: #111; border-style: solid; border-width: 0px 2px 2px 0; border-top: 1px solid #bbb;" | <span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>mid(12345)</nowiki></b></span> |
|||
<p style="margin-left:20pt;">Returns <span style="font-family: monospace,monospace; font-size:1em;">1</span>, using is the default <i>quantity</i> (1) of characters from the default <i>start position</i> of (0 - the beginning of the <i>string</i>).</p> |
|||
<span style="font-family: monospace,monospace; font-size:1em;"><b><nowiki>mid(12345, 1, 2)</nowiki></b></span> |
|||
<p style="margin-left:20pt;">Returns 2 characters beginning at <i>start position</i> 1, which is <span style="font-family: monospace,monospace; font-size:1em;">23</span>.</p> |
|||
Additional Examples |
|||
:[http://yabb.jriver.com/interact/index.php?topic=52809.0 An example that uses Mid() to re-order a date field.] |
|||
:[http://yabb.jriver.com/interact/index.php?topic=75891.0 An example that uses Mid() to output a number of stars based on an arbitrary rating value.] |
|||
|} |
|||
<div style="text-align:right;">([[#top|Back to top)]]</div> |
|||
=== <span id="Regex">Regex(…)</span> === |
=== <span id="Regex">Regex(…)</span> === |
||
Line 296: | Line 270: | ||
=== <span id="RemoveRight">RemoveRight(…)</span> === |
=== <span id="RemoveRight">RemoveRight(…)</span> === |
||
: Trims characters from the end of a string |
: Trims characters from the end of a string |
||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
||
Line 312: | Line 286: | ||
=== <span id="Replace">Replace(…)</span> === |
=== <span id="Replace">Replace(…)</span> === |
||
: Replace or remove a string segment |
: Replace or remove a string segment |
||
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
{| style="width: 100%; border-spacing: 0; border: 0px solid black;" align="top" cellpadding="3" cellspacing="0" |
||
Line 387: | Line 361: | ||
: Reverses the lexical order of the name list to <span style="font-family: monospace,monospace; font-size:1em;">Paul Simon; Art Garfunkel</span>. |
: Reverses the lexical order of the name list to <span style="font-family: monospace,monospace; font-size:1em;">Paul Simon; Art Garfunkel</span>. |
||
'''Please Note''': These examples were simplified and ignore the commas in the string arguments. For these expressions to work properly (when entered directly), you would need to escape the comma in the string literal: {{monospace|Unswap(Simon/, Paul; Garfunkel/, Art)}}. However, this function is typically used with a field value (or the output of another function), and would therefore be treated as a single argument even if the resulting string contains a comma. See [[Expression Language#Function Arguments|Function Arguments]] for further details. |
'''Please Note''': These examples were simplified and ignore the commas in the string arguments. For these expressions to work properly (when entered directly), you would need to escape the comma in the string literal: {{monospace|Unswap(Simon/, Paul; Garfunkel/, Art)}}. However, this function is typically used with a field value (or the output of another function), and would therefore be treated as a single argument even if the resulting string contains a comma. See [[Expression Language#Function Arguments|Function Arguments]] for further details. |
||
}} |
|||
=== <span id="MoveArticles">MoveArticles(…)</span> === |
|||
: Takes The Beatles and reverses it to Beatles, The. |
|||
{{function description box |
|||
| name=MoveArticles |
|||
| arguments=string |
|||
| description= |
|||
The [[#MoveArticles|MoveArticles()]] function is similar to the Swap() function, except that it operates on strings with prefixed articles (such as "The Beatles" or "A Flock of Seagulls".) |
|||
| examples= |
|||
'''{{monospace|<nowiki>MoveArticles(The Beatles)</nowiki>}}''' |
|||
: Moves the article to the end of the name <span style="font-family: monospace,monospace; font-size:1em;">Beatles, The</span>. |
|||
}} |
|||
=== <span id="Unswap">UnMoveArticles(…)</span> === |
|||
: Takes Beatles, The and reverses it to restore the normal word order. |
|||
{{function description box |
|||
| name=UnMoveArticles |
|||
| arguments=string |
|||
| description= |
|||
The [[#UnMoveArticles|UnMoveArticles()]] function is the opposite of the MoveArticles() function. It is used to restore the normal order of an band name with a prefix article in a string (converting Beatles, The into The Beatles). |
|||
| examples= |
|||
'''{{monospace|<nowiki>UnMoveArticles(Flock of Seagulls, A)</nowiki>}}''' |
|||
: Restores the normal order of the name to <span style="font-family: monospace,monospace; font-size:1em;">A Flock of Seagulls</span>. |
|||
'''Please Note''': These examples were simplified and ignore the commas in the string arguments. For these expressions to work properly (when entered directly), you would need to escape the comma in the string literal: {{monospace|UnMoveArticles(Beatles/, The)}}. However, this function is typically used with a field value (or the output of another function), and would therefore be treated as a single argument even if the resulting string contains a comma. See [[Expression Language#Function Arguments|Function Arguments]] for further details. |
|||
}} |
}} |
Revision as of 20:19, 7 March 2017
- See also: {{#if:Expression Language |[[:Expression Language{{#if:||{{{l1}}}}}]] |Error: Template must be given at least one article name
}}{{#if:Expression Language#Function Index|{{#if:|, | and }} [[:Expression Language#Function Index{{#if:Function Index||Function Index}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{3}}}{{#if:||{{{l3}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{4}}}{{#if:||{{{l4}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{5}}}{{#if:||{{{l5}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{6}}}{{#if:||{{{l6}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{7}}}{{#if:||{{{l7}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{8}}}{{#if:||{{{l8}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{9}}}{{#if:||{{{l9}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{10}}}{{#if:||{{{l10}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{11}}}{{#if:||{{{l11}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{12}}}{{#if:||{{{l12}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{13}}}{{#if:||{{{l13}}}}}]]
}}{{#if:|{{#if:|, |, and }} [[:{{{14}}}{{#if:||{{{l14}}}}}]]
}}{{#if:|, and [[:{{{15}}}{{#if: || }}]]
}}{{#if:| —
Error: Too many links specified (maximum is 15)
}}
The functions in this section are used primarily to manipulate strings. Since the Media Center expression language is primarily string-oriented, these functions provide a means to manipulate field values or the output from other expressions.
Clean(…)
- Clean a string to be used for various operations.
Description | Clean(string, mode)
The Clean() function is generally used to sanitize a string by stripping empty brackets, remove superfluous dash characters, eliminate leading or trailing articles, or replace filesystem-illegal characters. It is typically employed before some operation such as Rename to clean the product of joining various fields, some of which may be empty, or to produce filesystem-safe filenames. It may be used for a variety of purposes, however. Available mode values:
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Examples | clean([album] - [date])
clean(The Beatles, 1)
clean(AC//DC: Back In Black, 3)
clean(\//:*?"<>|, 3)
|
FixCase(…)
- Changes the case of a given string.
Description | FixCase(string, mode)
The FixCase() function will convert the supplied text string according to the specified mode. Available mode values:
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Examples | fixcase(enjoy the silence)
fixcase(enjoy the silence, 1)
fixcase(MY ALbUm IS cAlLeD: adam, 4)
fixcase(MY ALbUm IS cAlLeD: adam, 5)
|
FixSpacing(…)
- Intelligently splits adjacent camel-cased words.
Description | FixSpacing(string, mode)
The FixSpacing() function inserts spaces between adjacent camel-cased words in string. It is useful for helping to clean and convert metadata that favors compactness over standard sentence structure. Available mode values:
| ||||
---|---|---|---|---|---|
Examples | fixspacing(OneWorld)
fixspacing([name], 1)
fixspacing(Another [name])
|
Hexify(…)
- Hexifies a string to make it suitable for web usage.
Description | Hexify(string)
The Hexify() function URI encodes a string to make it useable by a browser or search engine. Hexify() is typically used by expressions generating or working on URLs in Media Center's Link Manager. |
---|---|
Examples | hexify(Oasis - /(What's The Story/) Morning Glory?)
|
Left(…)
- Retrieves a specified number of characters from the left of a string.
Description | Left(string, quantity)
The Left() function retrieves no more than quantity characters from the left of the string. |
---|---|
Examples | left([filename], 3)
|
Length(…)
- Returns the number of characters in a string.
Description | Length(string)
The Length() function returns the number of characters contained in string. |
---|---|
Examples | length(A Simple Plan)
if(compare(length([filename]), >=, 68), Long, Short)
|
Mid(…)
- Retrieves specified characters from a string.
Description | Mid(string, start position, quantity)
The Mid() function returns a specified quantity of characters from the start position in string. The start position is 0-based (i.e. the first character is considered position 0). A quantify of -1 returns all characters from the start positionning to the end of string. |
---|---|
Examples | mid(12345)
mid(12345, 1, 2)
Additional Examples: |
Regex(…)
- Regular expression pattern matching and capture.
Description | regex(string, regexp, run mode, case sensitivity)
The Regex() function performs regular expression (RE) pattern matching on a string. The string is evaluated against the regular expression regexp, and run mode dictates the values output by Regex(). The three modes allow for match testing, capture output, or silent operation. All match captures are placed into special variables referenced as [R1], [R2], ... [R9], which can be used in later in the expression. The contents of the captures [R1] ... [R9] are available until the end of the expression, or Regex() is run again, whereby they are replaced. The regular expression implementation used prior to Media Center 19 is the Microsoft 2010 TR1 engine, and in Media Center 19 it is the Boost engine. Additional information is available regarding the full syntax and other implementation details. Available run mode values:
The case sensitivity argument toggles the case-sensitivity of regular expression matching. Note that case insensitivity does not apply to characters inside a character class [ ]. Use both uppercase and lowercase characters when necessary to match either case (e.g. [aAbB] to match either uppercase or lowercase A or B). Available case sensitivity values:
The regular expression language assigns special meaning to many characters. A few of these meta-characters, such as forward slash /, comma , and both ( and ) are also reserved and used by the Media Center expression language. To force the Media Center expression engine to ignore the meta-characters in regexp, surround the entire regular expression with /# #/. This is one of Media Center's escapements, which tells the expression engine to ignore everything inside, so that the entire, uninterpreted regexp can be provided to the Regex() regular expression evaluator. Although surrounding regexp by /# #/ is not necessary or required when no conflicting characters are in use, and you may manually escape the expression languages meta-characters with a forward slash /, it is probably a safe practice to always encase every regexp within /# #/. Argument run mode is optional (defaults to 0). Argument case sensitivity is optional (defaults to 0). | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Examples | ifelse(regex([name], /#^(the|an|a)\b#/, 0, 1), Fix your case!)
Searches the name field for any of the lowercase articles the, and and a at the beginning of name, and outputs Fix your case! when the match succeeds. The run mode is 0 which is a test and capture mode, and case sensitivity is enabled. if(regex([artist], /#([[:punct:]])#/, 0), [R1] --> [Artist], No Punctuation) Using the default mode 0, Regex() will output a Boolean for use inside a conditional to cause some action to occur based on the match success or failure. This example matches against the artist field looking for any punctuation character. If the match succeeds (a punctuation character was found), that character is output followed by the string --> and the artist. In there was no match, the string No Punctuation is output. regex(D03T02 some track.mp3, /#^D(\d+)T(\d+)#/, 1)Disc: [R1], Track: [R2] The string is matched against the regexp that is looking for a D followed by any number of digits, followed by a T and then more digits. Those digits were captured, and later used to output the value Disc: 03, Track: 02. regex([filename (name)], /#^(\d+)-#/, -1)Track number is [R1] Using run mode -1, the file's name is pattern tested against the regexp which is looking for leading digits followed by a dash. Those digits are captured in buffer [R1] which is used later in the expression. If the file name was 2-foo.mp3, the output would be Track number is 2. regex([filename], /#(\d{1,2})\.(\d{1,2}).(\d{4})#/, -1)[R3]//[R1]//[R2] Matches and captures a date formatted as dd.mm.yyyy anywhere within the filename, and rearranges it in a standard format of yyyy/mm/dd. Since run mode is -1, no output occurs. However, captured match segments are made available for subsequent use. The three captures, [R1], [R2] and [R3] are arranged in the textual output so that we get the desired year/month/day ordering, such as 2011/08/19. |
RemoveCharacters(…)
- Removes a list of characters from a string.
Description | removecharacters(string, character list, mode)
The RemoveCharacters() function will remove from string any characters in the character list. The characters removed depend upon the mode specified. The function operates in a case-sensitive manner. Available mode values:
Argument mode is optional (defaults to 0). | ||||||||
---|---|---|---|---|---|---|---|---|---|
Examples | removecharacters(Paper, Ppr)
Removes P, p, and r from Paper, resulting in ae. The default mode 0 is in effect, removing all instances of the characters specified in the character list. removecharacters(Paper, Ppr, 1) With mode 1 set, only the initial character P is removed, resulting in aper. removecharacters(Paper, Ppr, 2) In mode 2, only one character from the end of the string are removed, leaving "Pape. removecharacters(Paper, Ppr, 3) Both the front and back are affected in mode 3, causing the removal of the leading P and trailing r resulting in ape. removecharacters([artist], /(/)) Removes any ( and ) characters from anywhere within the [artist] field. |
RemoveLeft(…)
- Trims characters from the beginning of a string.
Description | removeleft(string, quantity)
The RemoveLeft() function removes a specified quantity of characters from the left side of a string. If the quantity is larger than the length of the string, the output will be empty. |
---|---|
Examples | removeleft(Good Deeds, 5)
Removes the first 5 characters from resulting in Deeds being output. |
RemoveRight(…)
- Trims characters from the end of a string
Description | removeright(string, quantity)
The RemoveRight() function removes a specified quantity of characters from the right side of a string. If the quantity is larger than the length of the string, the output will be empty. |
---|---|
Examples | removeright(03-02-1959,5)
Removes the last 5 characters from the given date, leaving only the month and year 03-02. |
Replace(…)
- Replace or remove a string segment
Description | replace(string, old, new)
The Replace() function replaces all instances of old within string with new. If new is unspecified, it defaults to an empty value, causing old to be removed. Replace() operates in a case-sensitive manner. Argument new is optional (defaults to EMPTY). |
---|---|
Examples | replace(The Daily Show with John Oliver, hn Oliver, n Stewart)
Now that John Oliver has completed his summer stand-in for Jon Stewart, it is time for a replacement. The old sequence hn Oliver will be replaced with the new sequence n Stewart, resulting in The Daily Show with Jon Stewart. replace(Sample String, s, Replaced) In this example, the original string does not contain the old value s anywhere, so no replacement occurs and the original string is returned. replace(Led Zeppelin.[remastered], .[remastered]) Removes the trailing old value .[remastered] from the original string, resulting in Led Zeppelin. Because no new string is specified, the default empty value is used as a replacement, effectively stripping the old value. |
Right(…)
- Retrieves a specified number of characters from the right of a string.
Description | right(string, quantity)
The Right() function retrieves the specified quantity of characters from the right of the string. If quantity is larger than the length of string, the original string is returned. |
---|---|
Examples | right([filename], 3)
Returns the last three characters from the filename (typically this is the file's suffix). |
Swap(…)
- Takes Firstname Lastname and swaps to Lastname, Firstname.
Description | Swap(string)
The Swap() function is used to reverse the order of a personal name in a string (converting Firstname Lastname into Lastname, Firstname). The function has special handling for strings that end with Jr., Sr., I, II, III, IV, V (so that these common suffixes are handled properly), and it can also handle semicolon-delimited string lists (such as [Artist], [Actors], and [Director]). |
---|---|
Examples | swap(Paul Simon)
swap(Sammy Davis Jr.)
swap(Paul Simon; Art Garfunkel)
|
Unswap(…)
- Takes Lastname, Firstname and reverses it to Firstname Lastname.
Description | Unswap(string)
The Unswap() function is the opposite of the Swap() function. It is used to restore the normal western-style order of a personal name in a string (converting Lastname, Firstname into Firstname Lastname). This command also works properly with semicolon-delimited list data (such as the [Artist] field), and like the Swap() command, it handles common name suffixes such as Jr., Sr., I, II, III, IV, V, etc. |
---|---|
Examples | Unswap(Simon, Paul)
Unswap(Simon, Paul; Garfunkel, Art)
Please Note: These examples were simplified and ignore the commas in the string arguments. For these expressions to work properly (when entered directly), you would need to escape the comma in the string literal: Unswap(Simon/, Paul; Garfunkel/, Art). However, this function is typically used with a field value (or the output of another function), and would therefore be treated as a single argument even if the resulting string contains a comma. See Function Arguments for further details. |
MoveArticles(…)
- Takes The Beatles and reverses it to Beatles, The.
Description | MoveArticles(string)
The MoveArticles() function is similar to the Swap() function, except that it operates on strings with prefixed articles (such as "The Beatles" or "A Flock of Seagulls".) |
---|---|
Examples | MoveArticles(The Beatles)
|
UnMoveArticles(…)
- Takes Beatles, The and reverses it to restore the normal word order.
Description | UnMoveArticles(string)
The UnMoveArticles() function is the opposite of the MoveArticles() function. It is used to restore the normal order of an band name with a prefix article in a string (converting Beatles, The into The Beatles). |
---|---|
Examples | UnMoveArticles(Flock of Seagulls, A)
Please Note: These examples were simplified and ignore the commas in the string arguments. For these expressions to work properly (when entered directly), you would need to escape the comma in the string literal: UnMoveArticles(Beatles/, The). However, this function is typically used with a field value (or the output of another function), and would therefore be treated as a single argument even if the resulting string contains a comma. See Function Arguments for further details. |