# Utils

(utils)

## Overview

The `Utils` scripting object provides a range of utility methods for data transformation, formatting, and validation. It includes functionality for handling Base64 encoding and decoding, byte array manipulation, and string transformations such as escaping markup, formatting, and hashing. This makes it a versatile tool for managing data in different formats.

Key methods include `base64ToBytes`, which converts Base64-encoded strings to byte arrays, and `bytesToBase64`, which performs the reverse operation. The `dateFormat` method allows dates to be formatted based on specified patterns, with support for custom timezones and locales. Similarly, `numberFormat` enables precise number formatting, including locale-specific options.

Advanced string operations such as `stringReplace`, `stringFormat`, and `stringTrim` are complemented by security-focused methods like `stringMD5HashBase16` and `stringPBKDF2Hash`, providing robust options for hashing and validation. For example, `validatePBKDF2Hash` ensures that a given password matches a hash, supporting modern cryptographic standards like SHA256.

The object also facilitates Unicode character conversion, checks for related records using `hasRecords`, and parses strings into date objects with `parseDate`, offering rich functionality for varied use cases.

## Methods Summarized

| Type                                                                           | Name                                                                                                                                                 | Summary                                                                                                                                                                                                                                                                                                          |
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [base64ToBytes(base64String:)](#base64tobytes-base64string:)                                                                                         | Return the byte array representation of the Base64 value                                                                                                                                                                                                                                                         |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [base64ToString(base64String:)](#base64tostring-base64string:)                                                                                       | Return the String representation of the Base64 value                                                                                                                                                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [bytesToBase64(byteArray:)](#bytestobase64-bytearray:)                                                                                               | Return the Base64 value representation of the byteArray                                                                                                                                                                                                                                                          |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [bytesToHex(bytearray)](#bytestohex-bytearray)                                                                                                       |                                                                                                                                                                                                                                                                                                                  |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [bytesToString(byteArray:)](#bytestostring-bytearray:)                                                                                               | Return the string conversion of the byteArray                                                                                                                                                                                                                                                                    |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [createLargeNumber(value)](#createlargenumber-value)                                                                                                 | Creates a large number from a string, use this if you want to create numbers that are larger the a Double floating point number, So if you want to keep precision exactly correct without any rounding, or you want to hold very large numbers that can't be hold correctly in a double you can use this method. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [dateFormat(date, format)](#dateformat-date-format)                                                                                                  | Format a date object to a text representation.                                                                                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [dateFormat(date, format, timezone)](#dateformat-date-format-timezone)                                                                               | Format a date object to a text representation using the format and timezone given.                                                                                                                                                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [dateFormat(date, format, language, country)](#dateformat-date-format-language-country)                                                              | Format a date object to a text representation.                                                                                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [dateFormat(date, format, timezone, language, country)](#dateformat-date-format-timezone-language-country)                                           | Format a date object to a text representation using the format, timezone, language and country given.                                                                                                                                                                                                            |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getUnicodeCharacter(unicodeCharacterNumber)](#getunicodecharacter-unicodecharacternumber)                                                           | Returns a string containing the character for the unicode number.                                                                                                                                                                                                                                                |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [hasRecords(foundset)](#hasrecords-foundset)                                                                                                         | Returns true if the (related)foundset exists and has records.                                                                                                                                                                                                                                                    |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [hasRecords(record, relationString)](#hasrecords-record-relationstring)                                                                              | Returns true if the (related)foundset exists and has records.                                                                                                                                                                                                                                                    |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [hexToBytes(hex)](#hextobytes-hex)                                                                                                                   |                                                                                                                                                                                                                                                                                                                  |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [hexToString(hex)](#hextostring-hex)                                                                                                                 |                                                                                                                                                                                                                                                                                                                  |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isMondayFirstDayOfWeek()](#ismondayfirstdayofweek)                                                                                                  | Returns true when Monday is the first day of the week for your current locale setting.                                                                                                                                                                                                                           |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [numberFormat(number, digits)](#numberformat-number-digits)                                                                                          | Format a number to have a defined fraction.                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [numberFormat(number, digits, language, country)](#numberformat-number-digits-language-country)                                                      | Format a number to have a defined fraction.                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [numberFormat(number, format)](#numberformat-number-format)                                                                                          | Format a number to specification.                                                                                                                                                                                                                                                                                |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [numberFormat(number, format, language, country)](#numberformat-number-format-language-country)                                                      | Format a number to specification.                                                                                                                                                                                                                                                                                |
| [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date)       | [parseDate(date, format)](#parsedate-date-format)                                                                                                    | Parse a string to a date object.                                                                                                                                                                                                                                                                                 |
| [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date)       | [parseDate(date, format, timezone)](#parsedate-date-format-timezone)                                                                                 | Parse a string to a date object.                                                                                                                                                                                                                                                                                 |
| [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date)       | [parseDate(date, format, language, country)](#parsedate-date-format-language-country)                                                                | Parse a string to a date object.                                                                                                                                                                                                                                                                                 |
| [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date)       | [parseDate(date, format, timezone, language, country)](#parsedate-date-format-timezone-language-country)                                             | Parse a string to a date object.                                                                                                                                                                                                                                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringEscapeMarkup(textString)](#stringescapemarkup-textstring)                                                                                     | Returns the escaped markup text (HTML/XML).                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringEscapeMarkup(textString, escapeSpaces)](#stringescapemarkup-textstring-escapespaces)                                                          | Returns the escaped markup text (HTML/XML).                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringEscapeMarkup(textString, escapeSpaces, convertToHtmlUnicodeEscapes)](#stringescapemarkup-textstring-escapespaces-converttohtmlunicodeescapes) | Returns the escaped markup text (HTML/XML).                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringFormat(text\_to\_format, parameters)](#stringformat-text_to_format-parameters)                                                                | Formats a string according to format specifiers and arguments.                                                                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringFormat(text, format)](#stringformat-text-format)                                                                                              | Format a string using mask.                                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringIndexReplace(text, i\_start, i\_size, replacement\_text)](#stringindexreplace-text-i_start-i_size-replacement_text)                           | Replaces a portion of a string with replacement text from a specified index.                                                                                                                                                                                                                                     |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringInitCap(text)](#stringinitcap-text)                                                                                                           | Returns all words starting with capital chars.                                                                                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringLeft(text, i\_size)](#stringleft-text-i_size)                                                                                                 | Returns a string with the requested number of characters, starting from the left.                                                                                                                                                                                                                                |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringLeftWords(text, numberof\_words)](#stringleftwords-text-numberof_words)                                                                       | Returns the number of words, starting from the left.                                                                                                                                                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringMD5HashBase16(textString)](#stringmd5hashbase16-textstring)                                                                                   | Returns the md5 hash (encoded as base16) for specified text.                                                                                                                                                                                                                                                     |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringMD5HashBase64(textString)](#stringmd5hashbase64-textstring)                                                                                   | Returns the md5 hash (encoded as base64) for specified text.                                                                                                                                                                                                                                                     |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringMiddle(text, i\_start, i\_size)](#stringmiddle-text-i_start-i_size)                                                                           | Returns a substring from the original string.                                                                                                                                                                                                                                                                    |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringMiddleWords(text, i\_start, numberof\_words)](#stringmiddlewords-text-i_start-numberof_words)                                                 | Returns a substring from the original string.                                                                                                                                                                                                                                                                    |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringPBKDF2Hash(textString)](#stringpbkdf2hash-textstring)                                                                                         | Returns the PBKDF2 hash for specified text.                                                                                                                                                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringPBKDF2Hash(textString, iterations)](#stringpbkdf2hash-textstring-iterations)                                                                  | Returns the PBKDF2 hash for specified text.                                                                                                                                                                                                                                                                      |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [stringPatternCount(text, toSearchFor)](#stringpatterncount-text-tosearchfor)                                                                        | Returns the number of times searchString appears in textString.                                                                                                                                                                                                                                                  |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [stringPosition(textString, toSearchFor, i\_start, i\_occurrence)](#stringposition-textstring-tosearchfor-i_start-i_occurrence)                      | Returns the position of the string to search for, from a certain start position and occurrence.                                                                                                                                                                                                                  |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringReplace(text, search\_text, replacement\_text)](#stringreplace-text-search_text-replacement_text)                                             | Replaces a portion of a string with replacement text.                                                                                                                                                                                                                                                            |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringReplaceTags(text, scriptable)](#stringreplacetags-text-scriptable)                                                                            | Returns the text with %%tags%% replaced, based on provided record or foundset or form.                                                                                                                                                                                                                           |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringRight(text, i\_size)](#stringright-text-i_size)                                                                                               | Returns a string with the requested number of characters, starting from the right.                                                                                                                                                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringRightWords(text, numberof\_words)](#stringrightwords-text-numberof_words)                                                                     | Returns the number of words, starting from the right.                                                                                                                                                                                                                                                            |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringToBase64(string:)](#stringtobase64-string:)                                                                                                   | Return the Base64 representation of the string                                                                                                                                                                                                                                                                   |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [stringToBytes(string:)](#stringtobytes-string:)                                                                                                     | Return the byte array representation of the string                                                                                                                                                                                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringToHex(string)](#stringtohex-string)                                                                                                           |                                                                                                                                                                                                                                                                                                                  |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [stringToNumber(textString)](#stringtonumber-textstring)                                                                                             | Filters characters out of from a string and leaves digits, returns the number.                                                                                                                                                                                                                                   |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [stringToNumber(textString, decimalSeparator)](#stringtonumber-textstring-decimalseparator)                                                          | Filters characters out of from a string and leaves digits, returns the number.                                                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [stringTrim(textString)](#stringtrim-textstring)                                                                                                     | Returns the string without leading or trailing spaces.                                                                                                                                                                                                                                                           |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [stringWordCount(text)](#stringwordcount-text)                                                                                                       | Returns the number of words in the text string.                                                                                                                                                                                                                                                                  |
| [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date)       | [timestampToDate(date)](#timestamptodate-date)                                                                                                       | Returns a datestamp from the timestamp (sets hours,minutes,seconds and milliseconds to 0).                                                                                                                                                                                                                       |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [validatePBKDF2Hash(password, hash)](#validatepbkdf2hash-password-hash)                                                                              | Validates the given password against the given hash.                                                                                                                                                                                                                                                             |

## Methods Detailed

### base64ToBytes(base64String:)

Return the byte array representation of the Base64 value

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **base64String:** the Base64 encoded string to convert to byte array

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) byteArray representation of the base64 string using UTF-8 charset for conversion

**Sample**

```js
var string = utils.base64ToBytes(base64String);
```

### base64ToString(base64String:)

Return the String representation of the Base64 value

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **base64String:** the Base64 value to convert to String

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) String decoded representation of the Base64 value using UTF-8 charset for conversion

**Sample**

```js
var string = utils.base64ToString(base64Value);
```

### bytesToBase64(byteArray:)

Return the Base64 value representation of the byteArray

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **byteArray:** the byte array to convert to Base64 value

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) Base64 representation of the byte array using UTF-8 charset for conversion

**Sample**

```js
var string = utils.bytesToBase64(byteArray);
x`
```

### bytesToHex(bytearray)

**Parameters**

* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **bytearray** the byte array to convert to hex encoded string

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) returns hex encoded string from bytearray

**Sample**

```js
var string = utils.bytesToHex(byteArray);
```

### bytesToString(byteArray:)

Return the string conversion of the byteArray

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **byteArray:** the byte array to convert to

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) string representation of the byte array using UTF-8 charset for conversion

**Sample**

```js
var string = utils.bytesToString(byteArray);
```

### createLargeNumber(value)

Creates a large number from a string, use this if you want to create numbers that are larger the a Double floating point number, So if you want to keep precision exactly correct without any rounding, or you want to hold very large numbers that can't be hold correctly in a double you can use this method.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **value** the string literal that represents the number

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the resulting number as a java BigDecimal

**Sample**

```js
var textalNumber = utils.createLargeNumber("12345678901234567890.1234567890");
```

### dateFormat(date, format)

```
Format a date object to a text representation.
For NGClient/Titanium Client it will use the timezone of the client.
see #dateFormat(Date,String,String) for using the actual clients timezone.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'.
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)
```

**Parameters**

* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **date** the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to output

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the date as text

**Sample**

```js
var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss');
```

### dateFormat(date, format, timezone)

```
Format a date object to a text representation using the format and timezone given.
If the timezone is not given the timezone of the client itself will be used.
see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)
```

**Parameters**

* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **date** the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to output
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **timezone** The timezone string to use to parse the date (like GMT+3), if null then the timezone of the current client is used.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the date as text

**Sample**

```js
var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "UTC");
```

### dateFormat(date, format, language, country)

```
Format a date object to a text representation.
With language and/or country the locale will be created.
For NGClient/Titanium Client it will use the timezone of the client.
see #dateFormat(Date,String,String) for using the actual clients timezone.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'.
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)
```

**Parameters**

* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **date** the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to output
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the date as text

**Sample**

```js
var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "fr", "CA");
```

### dateFormat(date, format, timezone, language, country)

```
Format a date object to a text representation using the format, timezone, language and country given.
With the language and country given, the locale will be created.
If the timezone is not given the timezone of the client itself will be used.
see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)
```

**Parameters**

* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **date** the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to output
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **timezone** the timezone to use the format, if null then current client timezone is used.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the date as text

**Sample**

```js
var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "UTC", "fr", "CA");
```

### getUnicodeCharacter(unicodeCharacterNumber)

Returns a string containing the character for the unicode number.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **unicodeCharacterNumber** the number indicating the unicode character

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a string containing the unicode character

**Sample**

```js
//returns a big dot
var dot = utils.getUnicodeCharacter(9679);
```

### hasRecords(foundset)

Returns true if the (related)foundset exists and has records.\
Another use is, to pass a record and qualified relations string to test multiple relations/foundset at once

**Parameters**

* [JSFoundSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsfoundset) **foundset** the foundset to be tested

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if exists

**Sample**

```js
//test the orders_to_orderitems foundset
if (myElement.hasRecords(orders_to_orderitems))
{
	//do work on relatedFoundSet
}
//test the orders_to_orderitems.orderitems_to_products foundset to be reached from the current record
//if (myElement.hasRecords(foundset.getSelectedRecord(),'orders_to_orderitems.orderitems_to_products'))
//{
//	//do work on deeper relatedFoundSet
//}
```

### hasRecords(record, relationString)

Returns true if the (related)foundset exists and has records.\
Another use is, to pass a record and qualified relations string to test multiple relations/foundset at once

**Parameters**

* [JSRecord](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsrecord) **record** A JSRecord to test.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **relationString** The relation name.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the foundset/relation has records.

**Sample**

```js
//test the orders_to_orderitems foundset
if (myElement.hasRecords(orders_to_orderitems))
{
	//do work on relatedFoundSet
}
//test the orders_to_orderitems.orderitems_to_products foundset to be reached from the current record
//if (myElement.hasRecords(foundset.getSelectedRecord(),'orders_to_orderitems.orderitems_to_products'))
//{
//	//do work on deeper relatedFoundSet
//}
```

### hexToBytes(hex)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **hex** hex encoded string to be decoded into a byte array.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) a byte array from hex encoded string

**Sample**

```js
var array = utils.hexToBytes(hex);
```

### hexToString(hex)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **hex** ;

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) returns decoded string from hex

**Sample**

```js
var string = utils.hexToString(hex);
```

### isMondayFirstDayOfWeek()

Returns true when Monday is the first day of the week for your current locale setting.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if Monday is first day of the week in current locale

**Sample**

```js
if(utils.isMondayFirstDayOfWeek())
{
	//a date calculation
}
```

### numberFormat(number, digits)

Format a number to have a defined fraction.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **number** the number to format
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **digits** nr of digits

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting number in text

**Sample**

```js
var textalNumber = utils.numberFormat(16.749, 2); //returns 16.75
```

### numberFormat(number, digits, language, country)

Format a number to have a defined fraction.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **number** the number to format
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **digits** nr of digits
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting number in text

**Sample**

```js
var textalNumber = utils.numberFormat(16.749, 2, "fr", "CA"); //returns 16.75
```

### numberFormat(number, format)

Format a number to specification.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **number** the number to format
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting number in text

**Sample**

```js
var textalNumber2 = utils.numberFormat(100006.749, '#,###.00'); //returns 100,006.75
```

### numberFormat(number, format, language, country)

Format a number to specification.

**Parameters**

* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **number** the number to format
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting number in text

**Sample**

```js
var textalNumber2 = utils.numberFormat(100006.749, '#,###.00', "fr", "CA"); //returns 100,006.75
```

### parseDate(date, format)

Parse a string to a date object. This parses the date using the TimeZone of the server Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **date** the date as text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to parse the date

**Returns:** [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) the date as date object

**Sample**

```js
var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss');
```

### parseDate(date, format, timezone)

Parse a string to a date object. Using the timezone that is given, if null then it formats it with the clients timezone.

see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **date** the date as text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to parse the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **timezone** The timezone string to use to parse the date (like GMT+3)

**Returns:** [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) the date as date object

**Sample**

```js
var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss');
```

### parseDate(date, format, language, country)

Parse a string to a date object. Using language and country that are given,\
if null then it formats it with the locale of the client

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **date** the date as text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to parse the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) the date as date object

**Sample**

```js
var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss', 'en', 'US');
```

### parseDate(date, format, timezone, language, country)

Parse a string to a date object. Using the timezone, language and country that are given,\
if null then it formats it with the timezone and locale of the client

see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **date** the date as text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **format** the format to parse the date
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **timezone** The timezone string to use to parse the date (like GMT+3)
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **language** language used to create locale
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **country** country used along side language to create the locale

**Returns:** [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) the date as date object

**Sample**

```js
var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss', 'GMT+3', 'en', 'US');
```

### stringEscapeMarkup(textString)

Returns the escaped markup text (HTML/XML).

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the escaped text

**Sample**

```js
var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')
```

### stringEscapeMarkup(textString, escapeSpaces)

Returns the escaped markup text (HTML/XML).

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **escapeSpaces** indicating to escape spaces

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the escaped text

**Sample**

```js
var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')
```

### stringEscapeMarkup(textString, escapeSpaces, convertToHtmlUnicodeEscapes)

Returns the escaped markup text (HTML/XML).

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **escapeSpaces** indicating to escape spaces
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **convertToHtmlUnicodeEscapes** indicating to use unicode escapes

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the escaped text

**Sample**

```js
var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')
```

### stringFormat(text\_to\_format, parameters)

Formats a string according to format specifiers and arguments.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text\_to\_format** the text to format
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **parameters** the array with parameters

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the formatted text

**Sample**

```js
// the  format specifier has the syntax: %[argument_index$][flags][width][.precision]conversion
// argument index is 1$, 2$ ...
// flags is a set of characters that modify the output format
// typical values: '+'(The result will always include a sign), ','(The result will include locale-specific grouping separators)
// width is a non-negative decimal integer indicating the minimum number of characters to be written to the output
// precision is a non-negative decimal integer usually used to restrict the number of characters
// conversion is a character indicating how the argument should be formatted
// typical conversion values: b(boolean), s(string), c(character), d(decimal integer), f(floating number), t(prefix for date and time)
// Date/Time Conversions (used after 't' prefix):
		// 'H' 	Hour of the day for the 24-hour clock, formatted as two digits with a leading zero as necessary i.e. 00 - 23.
		// 'I' 	Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e. 01 - 12.
		// 'k' 	Hour of the day for the 24-hour clock, i.e. 0 - 23.
		// 'l' 	Hour for the 12-hour clock, i.e. 1 - 12.
		// 'M' 	Minute within the hour formatted as two digits with a leading zero as necessary, i.e. 00 - 59.
		// 'S' 	Seconds within the minute, formatted as two digits with a leading zero as necessary, i.e. 00 - 60 ("60" is a special value required to support leap seconds).
		// 'L' 	Millisecond within the second formatted as three digits with leading zeros as necessary, i.e. 000 - 999.
		// 'p' 	Locale-specific morning or afternoon marker in lower case, e.g."am" or "pm". Use of the conversion prefix 'T' forces this output to upper case.
		// 'z' 	RFC 822 style numeric time zone offset from GMT, e.g. -0800.
		// 'Z' 	A string representing the abbreviation for the time zone.
		// 'B' 	Locale-specific full month name, e.g. "January", "February".
		// 'b' 	Locale-specific abbreviated month name, e.g. "Jan", "Feb".
		// 'h' 	Same as 'b'.
		// 'A' 	Locale-specific full name of the day of the week, e.g. "Sunday", "Monday"
		// 'a' 	Locale-specific short name of the day of the week, e.g. "Sun", "Mon"
		// 'C' 	Four-digit year divided by 100, formatted as two digits with leading zero as necessary, i.e. 00 - 99
		// 'Y' 	Year, formatted as at least four digits with leading zeros as necessary, e.g. 0092 equals 92 CE for the Gregorian calendar.
		// 'y' 	Last two digits of the year, formatted with leading zeros as necessary, i.e. 00 - 99.
		// 'j' 	Day of year, formatted as three digits with leading zeros as necessary, e.g. 001 - 366 for the Gregorian calendar.
		// 'm' 	Month, formatted as two digits with leading zeros as necessary, i.e. 01 - 13.
		// 'd' 	Day of month, formatted as two digits with leading zeros as necessary, i.e. 01 - 31
		// 'e' 	Day of month, formatted as two digits, i.e. 1 - 31.

		// common compositions for date/time conversion
		// 'R' 	Time formatted for the 24-hour clock as "%tH:%tM"
		// 'T' 	Time formatted for the 24-hour clock as "%tH:%tM:%tS".
		// 'r' 	Time formatted for the 12-hour clock as "%tI:%tM:%tS %Tp". The location of the morning or afternoon marker ('%Tp') may be locale-dependent.
		// 'D' 	Date formatted as "%tm/%td/%ty".
		// 'F' 	ISO 8601 complete date formatted as "%tY-%tm-%td".
		// 'c' 	Date and time formatted as "%ta %tb %td %tT %tZ %tY", e.g. "Sun Jul 20 16:17:00 EDT 1969".

utils.stringFormat('%s Birthday: %2$tm %2$te,%2$tY',new Array('My',new Date(2009,0,1))) // returns My Birthday: 01 1,2009
utils.stringFormat('The time is: %1$tH:%1$tM:%1$tS',new Array(new Date(2009,0,1,12,0,0))) // returns The time is: 12:00:00
utils.stringFormat('My %s: %2$.0f, my float: %2$.2f',new Array('integer',10)) // returns My integer: 10, my float: 10.00
utils.stringFormat('Today is: %1$tc',new Array(new Date())) // returns current date/time as:  Today is: Fri Feb 20 14:15:54 EET 2009
utils.stringFormat('Today is: %tF',new Array(new Date())) // returns current date as: Today is: 2009-02-20
```

### stringFormat(text, format)

Format a string using mask.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the string to format
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **format** the format

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting text

**Sample**

```js
var formattedString = utils.stringFormat('0771231231', '(###)####-###'); //returns (077)1231-231
```

### stringIndexReplace(text, i\_start, i\_size, replacement\_text)

Replaces a portion of a string with replacement text from a specified index.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_start** the start index to work from
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_size** the size of the text to replace
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **replacement\_text** the replacement text

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the changed text string

**Sample**

```js
//returns 'this was a test'
var retval = utils.stringIndexReplace('this is a test',6,2,'was');
```

### stringInitCap(text)

Returns all words starting with capital chars.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the changed text

**Sample**

```js
//returns 'This Is A Test'
var retval = utils.stringInitCap('This is A test');
```

### stringLeft(text, i\_size)

Returns a string with the requested number of characters, starting from the left.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_size** the size of the text to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the result text string

**Sample**

```js
//returns 'this i'
var retval = utils.stringLeft('this is a test',6);
```

### stringLeftWords(text, numberof\_words)

Returns the number of words, starting from the left.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **numberof\_words** to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the string with number of words form the left

**Sample**

```js
//returns 'this is a'
var retval = utils.stringLeftWords('this is a test',3);
```

### stringMD5HashBase16(textString)

Returns the md5 hash (encoded as base16) for specified text.

NOTE: MD5 (Message-Digest Algorythm 5) is a hash function with a 128-bit hash value, for more info see: <http://en.wikipedia.org/wiki/MD5>

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting hashString

**Sample**

```js
var hashed_password = utils.stringMD5HashBase16(user_password)
```

### stringMD5HashBase64(textString)

Returns the md5 hash (encoded as base64) for specified text.

NOTE: MD5 (Message-Digest Algorythm 5) is a hash function with a 128-bit hash value, for more info see: <http://en.wikipedia.org/wiki/MD5>

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting hashString

**Sample**

```js
var hashed_password = utils.stringMD5HashBase64(user_password)
```

### stringMiddle(text, i\_start, i\_size)

Returns a substring from the original string.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_start** the start index to work from
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_size** the size of the text to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the result text string

**Sample**

```js
//returns 'his'
var retval = utils.stringMiddle('this is a test',2,3);
```

### stringMiddleWords(text, i\_start, numberof\_words)

Returns a substring from the original string.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_start** start word index
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **numberof\_words** the word count to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the string with number of words form the left and

**Sample**

```js
//returns 'is a'
var retval = utils.stringMiddleWords('this is a test',2,2);
```

### stringPBKDF2Hash(textString)

Returns the PBKDF2 hash for specified text. This method is preferred above the old MD5 hash for enhanced security.\
It uses a default of 9999 iterations. The string that is returned can only be used in the utils.validatePBKDF2Hash(password,thisReturnValue)\
to check if this hash is a result of that password.\
This will always be false: utils.stringPBKDF2Hash("test") == utils.stringPBKDF2Hash("test"). Because for the same string in multiply calls it will not generate the same hash.\
So you can only check it like this: utils.validatePBKDF2Hash("test",utils.stringPBKDF2Hash("test"))

NOTE: PBKDF2 is the key hash function for the PKCS (Public-Key Cryptography) standard, for more info see: <http://en.wikipedia.org/wiki/PBKDF2>

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting hashString

**Sample**

```js
var hashed_password = utils.stringPBKDF2Hash(user_password)
```

### stringPBKDF2Hash(textString, iterations)

Returns the PBKDF2 hash for specified text. This method is preferred above the old MD5 hash for enhanced security.\
From Servoy 2024.3.1 on this method will use SHA256 (HmacSHA256) as the Hash Algorithm.\
Before that it did use SHA1 (HmacSHA1) as the Hash Algorithm, this does result in the a different length of the hash.\
The total hash length (including interations of 9999) for SHA256 is 87 that was 63. So you need to make sure you can store at least 87 characters in your database. (but make sure you can handle more for future updates)

NOTE: PBKDF2 is the key hash function for the PKCS (Public-Key Cryptography) standard, for more info see: <http://en.wikipedia.org/wiki/PBKDF2>

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **iterations** how many hash iterations should be done, minimum should be 1000 or higher.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting hashString

**Sample**

```js
var hashed_password = utils.stringPBKDF2Hash(user_password,9999)
```

### stringPatternCount(text, toSearchFor)

Returns the number of times searchString appears in textString.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **toSearchFor** the string to search for

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the occurrenceCount that the search string is found in the text

**Sample**

```js
//returns 2 as count
var count = utils.stringPatternCount('this is a test','is');
```

### stringPosition(textString, toSearchFor, i\_start, i\_occurrence)

Returns the position of the string to search for, from a certain start position and occurrence.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **toSearchFor** the string to search
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_start** the start index to search from
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_occurrence** the occurrence

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the position

**Sample**

```js
//returns 4 as position
var pos = utils.stringPosition('This is a test','s',1,1)
```

### stringReplace(text, search\_text, replacement\_text)

Replaces a portion of a string with replacement text.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **search\_text** the string to search
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **replacement\_text** the replacement text

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the changed text string

**Sample**

```js
//returns 'these are cow 1 and cow 2.'
var retval = utils.stringReplace('these are test 1 and test 2.','test','cow');
```

### stringReplaceTags(text, scriptable)

Returns the text with %%tags%% replaced, based on provided record or foundset or form.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text tags to work with
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **scriptable** the javascript object or foundset,record,form to be used to fill in the tags

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the text with replaced tags

**Sample**

```js
//Next line places a string in variable x, whereby the tag(%%TAG%%) is filled with the value of the database column 'company_name' of the selected record.
var x = utils.stringReplaceTags("The companyName of the selected record is %%company_name%% ", foundset)
//var otherExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails);
//var recordExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails.getRecord(i);
//Next line places a string in variable y, whereby the tag(%%TAG%%) is filled with the value of the form variable 'x' of the form named 'main'.
//var y = utils.stringReplaceTags("The value of form variable is %%x%% ", forms.main);
//The next sample shows the use of a javascript object
//var obj = new Object();//create a javascript object
//obj['x'] = 'test';//assign an named value
//var y = utils.stringReplaceTags("The value of object variable is %%x%% ", obj);//use the named value in a tag
```

### stringRight(text, i\_size)

Returns a string with the requested number of characters, starting from the right.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **i\_size** the size of the text to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the result text string

**Sample**

```js
//returns 'a test'
var retval = utils.stringLeft('this is a test',6);
```

### stringRightWords(text, numberof\_words)

Returns the number of words, starting from the right.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** to process
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **numberof\_words** to return

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the string with number of words form the right

**Sample**

```js
//returns 'is a test'
var retval = utils.stringRightWords('this is a test',3);
```

### stringToBase64(string:)

Return the Base64 representation of the string

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **string:** the string to convert to Base64

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) Base64 encoded representation of the string using UTF-8 charset for conversion

**Sample**

```js
var string = utils.stringToBase64('This is A test');
```

### stringToBytes(string:)

Return the byte array representation of the string

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **string:** the string to convert to bytes

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) byte array representation of the string using UTF-8 charset for conversion

**Sample**

```js
var byteArray = utils.stringToBytes('This is A test');
```

### stringToHex(string)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **string** String to be encoded into hex

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) returns hex encoded string

**Sample**

```js
var hex = utils.stringToHex(string);
```

### stringToNumber(textString)

Filters characters out of from a string and leaves digits, returns the number. Uses locale decimal separator.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the resulting number

**Sample**

```js
//returns 65567
var retval = utils.stringToNumber('fg65gf567');
```

### stringToNumber(textString, decimalSeparator)

Filters characters out of from a string and leaves digits, returns the number. Decimal separator is specified as parameter.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **decimalSeparator** decimal separator

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the resulting number

**Sample**

```js
//returns 65.567
var retval = utils.stringToNumber('fg65gf.567','.');
```

### stringTrim(textString)

Returns the string without leading or trailing spaces.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textString** the text to process

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the resulting trimmed string

**Sample**

```js
//returns 'text'
var retval = utils.stringTrim('   text   ');
```

### stringWordCount(text)

Returns the number of words in the text string.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** the text to process

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) the word count

**Sample**

```js
//returns '4' as result
var retval = utils.stringWordCount('this is a test');
```

### timestampToDate(date)

Returns a datestamp from the timestamp (sets hours,minutes,seconds and milliseconds to 0).

**Parameters**

* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **date** object to be stripped from its time elements

**Returns:** [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) the stripped date object

**Sample**

```js
var date = utils.timestampToDate(application.getTimeStamp());
```

### validatePBKDF2Hash(password, hash)

Validates the given password against the given hash. The hash should be generated by one of the stringPBKDF2Hash(password \[,iteration]) functions. If hash is null or empty string the method will return false.\
This method can handle the older generated hash values based on SHA1 (HmacSHA1) and the new SHA256 (HmacSHA256) hash values.

NOTE: PBKDF2 is the key hash function for the PKCS (Public-Key Cryptography) standard, for more info see: <http://en.wikipedia.org/wiki/PBKDF2>

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** the password to test against
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **hash** the hash the password needs to validate to.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if his hash is valid for that password

**Sample**

```js
if (utils.validatePBKDF2Hash(user_password, hashFromDb)) {
   // logged in
}
```

***
