String Utilities
The built-in string functions are a mixed bag on both platforms: StringTrimLeft, StringTrimRight and StringReplace all modify their argument in place and return a count rather than the result, which is easy to trip over when the same variable is expected to still hold its original value a few lines later. StringSplit only accepts a single-character separator, so a delimiter like "::" or "->" from a hand-written log line or a simple protocol cannot be split with it at all. And there is no built-in StartsWith, EndsWith, Contains, case-insensitive equals, or numeric-string check on either platform. This header fills those gaps with a consistent rule: every function takes its input by value and returns a new string or a plain value, never mutating an argument. StrTrim, StrTrimLeft and StrTrimRight are safe to call on the same variable repeatedly without it changing underneath the caller. StrReplaceAll and StrRemove wrap the built-in StringReplace behind a pure interface. StrSplit accepts a delimiter of any length and returns the whole text as one part for an empty delimiter, rather than splitting between every character, which is the answer most callers actually want from an edge case that would otherwise need its own guard everywhere it is used. StrIsNumeric is a strict validator, not a "would StringToDouble tolerate this" check - one optional leading sign, at least one digit, at most one decimal point, no exponent form. It exists for validating a trader's typed input (a lot size, a price offset) where "12.3.4" or an empty string must be rejected outright rather than silently parsed into whatever StringToDouble happens to produce for malformed input. Notes and limitations - StrReverse operates on UTF-16 code units. It will not reorder a surrogate pair correctly, which covers characters outside the Basic Multilingual Plane; this is not a concern for symbol names, tickets or typical log text, which is what the function is for. True on both platforms. - StrIsNumeric deliberately rejects exponent notation ("1e5"). Use StringToDouble directly if a caller genuinely needs to accept that form. - StrSplit and StrJoin are plain string operations with no CSV-style quoting or escaping - a delimiter that appears inside a "quoted" field is still treated as a split point. Use this catalogue's CsvFile library for real CSV data. - Not thread-safe, which matches the single-threaded-per-chart execution model on both platforms; nothing here changes that.
Script · MT5 · v1.0 · Free
About String Utilities
String Utilities is a script for MetaTrader 5. It has 1 setting, such as Sample line. MQL source code included.
Files in the download: StringUtils.mq5.mqh, StringUtils.txt, StringUtilsDemo.ex5, StringUtilsDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Sample line | EURUSD :: BUY :: 0.10 lots | Sample line used for trim/split/join |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT5 Script · MQL5 Source Code