# Scripting: Variables and String Operations

> Managing data in scripts. Declaring variables, string concatenation, and data type conversions in the NiceProtect scripting language.

Canonical HTML: <https://www.niceprotect.com/help/strings_and_variables.htm>

## Strings and Variables Commands


Numbers are decimal by default. A value written with a **0x** (or **$**) prefix is hexadecimal; anything else is decimal. Arithmetic commands accept either form on input and write a decimal result, so the result of one operation can be used directly in the next.

**set** <value>, <accumulator> - Assigns a value to the accumulator.

**add** <v1>, <v2>, <acc> - Adds v1 and v2 (decimal result).

**sub** <v1>, <v2>, <acc> - Subtracts v2 from v1.

**mul** <v1>, <v2>, <acc> - Multiplies v1 by v2.

**div** <v1>, <v2>, <acc> - Integer division of v1 by v2.

**calc** <expression>, <acc> [, hex] - Evaluates an arithmetic expression with + - * / and parentheses; numbers may be decimal or hex. The result is decimal, or an unpadded HEX string if the third parameter is "hex".

**pack** <value>, <byte|word|dword|qword>, <le|be>, <acc> - Encodes a number as a fixed-width HEX byte string in little- or big-endian order, ready for putcode.

**unpack** <hex_bytes>, <le|be>, <acc> - Decodes a HEX byte string back into a decimal number.

**concat** <s1>, <s2>, <acc> - Concatenates string s1 and s2.

**chrtohex** <char>, <acc> - Converts a character to its HEX representation.

**hextochr** <hex>, <acc> - Converts a HEX string to a character.

**substr** <str>, <start>, <len>, <acc> - Extracts a substring (start is 1-based).

**length** <str>, <acc> - Gets string length.

**createstring** <char>, <count>, <acc> - Creates a string of repeating characters.

**rndbyte** <acc> - Stores a random byte (00..FF) as a two-digit HEX string in the accumulator.

**invert** <value>, <acc> - Encodes a value as a little-endian 4-byte HEX string (for example 0x00401011 becomes 11104000). Kept for compatibility; pack <value>, dword, le, <acc> is the clearer equivalent.

**settoclipboard** <text> - Copies text to the system clipboard.
