Namespace LrStringUtils
Access the functions directly from the imported namespace.
Summary
Functions
- LrStringUtils.byteString( number, precision )
-
Converts a number into a string representation suitable for displaying byte values. The function transforms the number appropriately and adds an indicator for bytes, kilobytes, megabytes, and so on.
For example, a number n between 1 and 1024 results in the string "n bytes". A number between 1024 and 1024^2 results in the string "n KB", and so on.
The byte indicators are "bytes", "KB", "MB", "GB", "TB", and "PB"
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. number
- (number) The number of bytes.
- 2. precision
- (optional, number) The total number of digits to show. left and right of the decimal point. The numeric value is rounded to this degree of precision, but trailing zeros are not removed. Default is 2. For example, using the default precision, the call
LrStringUtils.byteString( 2000000 )
returns "1.90 MB".
Return value
(string) The formatted string for the number of bytes. - LrStringUtils.compareStrings( string1, string2, treatNumberAsString )
-
Compares two strings using the operating system's localized string comparison. This is a wrapper for Lua's
table.sort
function, with this function as the comparator. Optional parameter treatNumberAsString decides whether to treat numbers is strings as numbers or normal string. For example,LrStringUtils.compareStrings("ab10c", "ab7c")
returns false because 10 > 7LrStringUtils.compareStrings("ab10c", "ab7c", true)
returns true because 1 < 7First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string1
- (string) The first string.
- 2. string2
- (string) The second string.
- 3. treatNumberAsString
- (optional, Boolean) Treat numbers in the string as normal string. Default is false
Return value
(Boolean) True if string1 < string2 according to the user's locale, false otherwise. - LrStringUtils.decodeBase64( string )
-
Decodes a string from base-64 encoding.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The base-64 encoded version of string
Return value
(string) The decoded version of string - LrStringUtils.encodeBase64( string )
-
Encodes a string in base-64 encoding.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to encode.
Return value
(string) The base-64 encoded version of the string. - LrStringUtils.isOnlyAscii( string )
-
Reports whether a string contains only 7-bit ASCII characters.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to evaluate.
Return value
(string) True if this string contains only 7-bit ASCII characters; false if any other data type is present or any byte is >= 128 - LrStringUtils.localizedStringSort( strings )
-
Sorts an array of strings in-place, using the operating system's localized string comparison.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. strings
- (table) An array of strings to sort.
Return value
(nil) Returns nothing. - LrStringUtils.lower( string )
-
Converts a string to lowercase using the operating system's localized case conversion. Unlike the Lua
string.lower
function, this function properly converts characters outside the 7-bit ASCII space.First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to convert.
Return value
(string) The lowercase version of the string. - LrStringUtils.numberToString( number, precision )
-
Formats a number as a string with an optional limit on precision. Does not insert separators for thousands. For example,
LrStringUtils.numberToString( 43500, 2 )
returns "43500.00", not "43,500.00").First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. number
- (number) The number to format.
- 2. precision
- (optional, number) The number of digits to allow after the decimal point.Default is 0.
Return value
(string) The formatted number string. - LrStringUtils.numberToStringWithSeparators( number, precision )
-
Formats a number as a string with thousands separators with an optional limit on precision. Insert thousands separators with the correct grouping according to user locale. For example,
LrStringUtils.numberToString( 43500, 2 )
returns "43,500.00", not "43500.00").Parameters
- 1. number
- (number) The number to format.
- 2. precision
- (optional, number) The number of digits to allow after the decimal point.Default is 0.
Return value
(string) The formatted number string. - LrStringUtils.trimWhitespace( string )
-
Removes whitespace from the beginning and end of a string.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to trim.
Return value
(string) The string without leading and trailing whitespace. - LrStringUtils.truncate( string, maxBytes )
-
Truncates a string to a maximum number of bytes, preserving the validity of the UTF-8 encoding.
First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to truncate.
- 2. maxBytes
- (number) The maximum number of bytes (not characters) to return
Return value
(string) The truncated string. - LrStringUtils.upper( string )
-
Converts a string to uppercase using the operating system's localized case conversion. Unlike the Lua
string.upper
function, this function properly converts characters outside the 7-bit ASCII space.First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. string
- (string) The string to convert.
Return value
(string) The uppercase version of the string.