This chapter explains how to work with strings in the K-Meleon macro language: Methods for general purpose, substitution and URL handling.
$position=index(<input>,<search>);
Returns the first position (zero-based index) of the search string in the input string (which is -1 when the search string is not found).
Parameters:
| Parameter | Required | Type | Value | Meaning |
|---|---|---|---|---|
| <input> | YES | STRING | A string | The string to process. |
| <search> | YES | STRING | A string | The string to search <input> for. |
$length=length(<string>);
Returns the length of the specified string.
$output=substr(<input>,<n>[,<length>]);
Returns the input string with the first n characters removed and optionally shortened to the specified length.
Parameters:
| Parameter | Required | Type | Value | Meaning |
|---|---|---|---|---|
| <input> | YES | STRING | A string | The string to process. |
| <n> | YES | INT | A number | The number of leading characters to remove. |
| <length> | NO | STRING | A number | The length of the returned string. |
$translation=_(<string>);
Returns the translation of a string as specified in K-Meleon's localization file. If no translation is found, the input string is returned.
Consequently, this method must be used for all strings that are presented to the user e.g. in dialogs, menus, the status bar or by injected scripts.
$output=gensub(<search>,<replace>,<target>,<input>);
General substitution. Returns the input string with matches of the search string replaced according to the specified replacement string and target.
Parameters:
| Parameter | Required | Type | Value | Meaning |
|---|---|---|---|---|
| <search> | YES | STRING | A string | The string to search <input> for. |
| <replace> | YES | STRING | A string | The string to replace <search> with. |
| <target> | YES | INT | N=1,2,3,... | Replace the Nth match of <search> only. |
| STRING | A string | Replace all matches of <search>.(1) | ||
| <input> | YES | STRING | A string | The string to process. |
(1) Only if <target> is beginning with "g" or "G", otherwise gensub() does nothing.
$output=gsub(<search>,<replace>,<input>);
Global substitution. Returns the input string with all matches of the search string replaced according to the specified replacement string - just like gensub(<search>,<replace>,g,<input>).
Parameters:
| Parameter | Required | Type | Value | Meaning |
|---|---|---|---|---|
| <search> | YES | STRING | A string | The string to search <input> for. |
| <replace> | YES | STRING | A string | The string to replace <search> with. |
| <input> | YES | STRING | A string | The string to process. |
$output=sub(<search>,<replace>,<input>);
Simple substitution. Returns the input string with the first match of the search string replaced according to the replacement string - just like gensub(<search>, <replace>,1,<input>).
Parameters:
| Parameter | Required | Type | Value | Meaning |
|---|---|---|---|---|
| <search> | YES | STRING | A string | The string to search <input> for. |
| <replace> | YES | STRING | A string | The string to replace <search> with. |
| <input> | YES | STRING | A string | The string to process. |
$basename=basename(<URL>[,<suffix>]);
Returns the specified URL with any leading directory components removed. If specified, also a trailing suffix is removed.
$dirname=dirname(<URL>);
Returns the specified URL's parent directory.
$hostname=hostname(<URL>);
Returns the specified URL's host name (domain name).
$URLComponent=urlencode(<string>);
Returns the specified string encoded as an URL component (so that it can be attached to an URL as a parameter).