TIA Portal Instructions

String and Text
Data Operations

Process text data like a pro. From dynamic label generation to protocol parsing, master every string manipulation instruction in your PLC.

Why process strings in a PLC?

While PLCs are primarily designed for binary and numerical logic, string operations are essential for modern industrial interfaces. They allow generating dynamic messages for HMIs, parsing barcodes or QR codes from scanners, and communicating with IT systems via formatted text protocols.

TIA Portal offers a robust set of instructions for managing STRING (ASCII) and WSTRING (Unicode) types, ensuring your machine can communicate clearly in any language.

Concatenation & Insertion

Building dynamic messages

CONCAT — Concatenate Strings

CONCAT

What it does

Combines two or more strings into a single output string. The source strings are appended in the order they are defined.

When to use it

Creating a full status message from a prefix and a variable name, or building a CSV line for logging.

Pro Tips

Always check the maximum length of your destination string to avoid truncation.

In SCL, you can use the '+' operator for simpler concatenation if supported.

Combine CONCAT with space characters to ensure readable HMI output.

INSERT — Insert into String

INSERT

What it does

Inserts a substring into an existing string at a specified character position (P).

When to use it

Adding unit symbols (like 'kg' or '°C') inside a dynamic text template.

Pro Tips

If P is 0, the string is inserted at the beginning.

If P is greater than the string length, the substring is appended at the end.

Useful for dynamic formatting of date/time strings.

Search & Modify

Analyzing text data

FIND — Search Substring

FIND

What it does

Searches for a specific pattern within a string and returns the starting position. Returns 0 if not found.

When to use it

Locating delimiters (like commas or semicolons) in a scanner input string.

Pro Tips

The search is case-sensitive. 'Error' is different from 'error'.

Use the returned position directly in a MID instruction to extract data.

In a loop, you can find multiple occurrences by updating the starting string.

REPLACE — Replace Part

REPLACE

What it does

Replaces a specific number of characters starting at position P with a new substring.

When to use it

Updating a variable part of a static message without rebuilding the whole string.

Pro Tips

To delete characters without adding new ones, use an empty string as the replacement.

Commonly used to swap placeholders like {val} with real values.

Be careful with character counts to avoid shifting the rest of the text unexpectedly.

Conversion & Extraction

Bridging numbers and text

VAL_STRG / STRG_VAL — Conversion

VAL_STRG

What it does

Converts numerical values (Int, Real) to String (VAL_STRG) or parses numbers from a String (STRG_VAL).

When to use it

Displaying a Real temperature in a custom text message or converting a serial port input to an Integer.

Pro Tips

Configure the FORMAT input to define decimals and sign behavior.

STRG_VAL is sensitive to the decimal separator (dot vs comma).

Check the status output to ensure the conversion was successful.

LEFT / RIGHT / MID — Extract

MID

What it does

Extracts a part of a string from the left, right, or a specific middle position (MID).

When to use it

Getting a prefix from a barcode or extracting a value between brackets.

Pro Tips

MID(IN, L, P) extracts L characters starting at position P.

If L exceeds available characters, the instruction returns everything until the end.

Essential for 'unboxing' data from third-party serial protocols.

STRING vs WSTRING

Choosing the right text format

PropertySTRINGWSTRING
EncodingASCII / Extended ASCIIUnicode (UTF-16)
Bytes per Char1 Byte2 Bytes
Max Length254 Characters16382 Characters
UsageStandard Western textInternational / Special chars
Memory ImpactLowHigh (Double)
SCL Prefix'' (Single quotes)W#''

Frequently Asked Questions

What is the maximum length of a STRING in TIA Portal?

A standard STRING can hold up to 254 characters. If you need more, you must use the WSTRING type which can handle up to 16,382 characters on S7-1500.

Why does my conversion VAL_STRG fail?

The most common reason is an insufficient destination string length or a mismatch in the FORMAT parameter (e.g., trying to fit a large REAL into a small STRING).

Can I use strings in optimized Data Blocks?

Yes, strings are fully supported in optimized DBs. However, remember that they always occupy their maximum defined size in memory, plus 2 bytes for length headers.

How to compare two strings in SCL?

You can use standard comparison operators (=, <>, <, >). TIA Portal compares strings character by character based on their ASCII/Unicode values.

Simplify your text processing

Complex parsing or label generation? T-IA Connect automates the creation of your string manipulation blocks.