> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Math and strings across languages

> How Lipi maps to MQL4, MQL5, NinjaScript, Pine Script and thinkScript for math and strings: absolute value, rounding, round to the tick size, smaller or larger of values, powers and roots, exponent and logarithms and more, with the differences that matter when converting.

Numeric and text functions. Each row maps one concept from Lipi to the other languages; the word in a cell is the relation, explained in the [language map overview](https://gocharting.com/docs/scripting/reference/language-map.md#relations).

| Concept | Lipi | MQL4 | MQL5 | NinjaScript | Pine Script | thinkScript |
| - | - | - | - | - | - | - |
| [Absolute value](#math-abs) | `math.abs` | Exact | Exact | Exact | Exact | Exact |
| [Rounding](#math-rounding) | `math.round`, `math.ceil`, `math.floor` | Caveat | Caveat | Differs | Caveat | Differs |
| [Round to the tick size](#math-round-to-tick) | `math.round_to_mintick` | Caveat | Absent | Caveat | Exact | Composite |
| [Smaller or larger of values](#math-min-max) | `math.min`, `math.max` | Caveat | Caveat | Caveat | Exact | Caveat |
| [Powers and roots](#math-power) | `math.pow`, `math.sqrt` | Exact | Exact | Caveat | Exact | Caveat |
| [Exponent and logarithms](#math-exp-log) | `math.exp`, `math.log`, `math.log10` | Caveat | Caveat | Caveat | Exact | Caveat |
| [Trigonometry](#math-trig) | `math.sin`, `math.cos`, `math.tan`, `math.asin`, `math.acos`, `math.atan` | Exact | Exact | Exact | Exact | Exact |
| [Degrees and radians](#math-angles) | `math.todegrees`, `math.toradians` | Absent | Absent | Absent | Exact | Absent |
| [Sign of a number](#math-sign) | `math.sign` | Absent | Absent | Caveat | Exact | Caveat |
| [Random number](#math-random) | `math.random` | Differs | Differs | Caveat | Caveat | Caveat |
| [Average and sum of values](#math-avg-sum) | `math.avg`, `math.sum` | Absent | Caveat | Caveat | Caveat | Differs |
| [Number to text](#str-tostring) | `str.tostring` | Caveat | Caveat | Caveat | Caveat | Differs |
| [Text to number](#str-tonumber) | `str.tonumber` | Caveat | Caveat | Caveat | Exact | Absent |
| [Length of text](#str-length) | `str.length` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Upper and lower case](#str-case) | `str.upper`, `str.lower` | Differs | Differs | Caveat | Exact | Absent |
| [Find text](#str-search) | `str.contains`, `str.pos`, `str.startswith`, `str.endswith` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Part of a text](#str-substring) | `str.substring` | Differs | Differs | Differs | Caveat | Absent |
| [Replace text](#str-replace) | `str.replace`, `str.replace_all` | Differs | Differs | Caveat | Differs | Absent |
| [Split text](#str-split) | `str.split` | Caveat | Caveat | Caveat | Exact | Absent |
| [Trim spaces](#str-trim) | `str.trim` | Caveat | Caveat | Exact | Exact | Absent |
| [Repeat text](#str-repeat) | `str.repeat` | Caveat | Caveat | Caveat | Caveat | Absent |
| [Match a pattern](#str-match) | `str.match` | Absent | Absent | Caveat | Caveat | Absent |
| [Join texts](#str-concat) | `+` | Caveat | Caveat | Caveat | Exact | Caveat |

Each section below gives the Lipi construct first, then the construct in each language, with a note wherever behaviour differs. The language name links to the documentation the row was checked against.

## Absolute value

The absolute value of `number`: its magnitude, with the sign removed.

In Lipi: `math.abs`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathabs#MathAbs) | `MathAbs` | Exact | |
| [MQL5](https://www.mql5.com/en/docs/math/mathabs) | `MathAbs` | Exact | |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/basic_syntax.htm) | `Math.Abs` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_math.abs) | `math.abs` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/AbsValue) | `AbsValue` | Exact | |

## Rounding

Rounds `number` to the nearest whole number and returns an int.

In Lipi: `math.round`, `math.ceil`, `math.floor`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathround) | `MathRound, MathCeil, MathFloor` | Equivalent, with a caveat | All three return double, not int, and take no precision argument; cast to int when a count is needed. Numbers and types: result type is double, where Lipi rounding returns int. |
| [MQL5](https://www.mql5.com/en/docs/math/mathround) | `MathRound, MathCeil, MathFloor` | Equivalent, with a caveat | All three return double, not int, and MathRound has no decimals argument. Cast to int, or use NormalizeDouble for decimal places. Numbers and types: Results are double; Lipi's one-argument round, ceil and floor return int. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | `Math.Round, Math.Ceiling, Math.Floor` | Looks alike, behaves differently | All three return double, not int. Math.Round on a midpoint defaults to round-half-to-even (2.5 gives 2); cast to int for a whole number. Numbers and types: Return type is double; Lipi's one-argument forms return int. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.round, math.ceil, math.floor` | Equivalent, with a caveat | Pine rounds ties up (toward positive infinity); Lipi rounds ties away from zero, so -2.5 gives -3 in Lipi and -2 in Pine. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Round) | `Round, RoundUp, RoundDown, Ceil, Floor` | Looks alike, behaves differently | Round() keeps 2 decimals by default, while Lipi math.round with no precision gives a whole int; RoundDown truncates toward zero, unlike floor. Numbers and types: thinkScript results stay doubles; Lipi ceil, floor and one-argument round return int. |

## Round to the tick size

Rounds `number` to the nearest multiple of `syminfo.mintick` for the chart symbol.

In Lipi: `math.round_to_mintick`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/convert/normalizedouble#NormalizeDouble) | `NormalizeDouble` | Equivalent, with a caveat | Rounds to a decimal count (0-8), usually Digits(), not to a tick multiple; differs when the tick is not a power of ten. |
| [MQL5](https://www.mql5.com/en/docs/convert/normalizedouble) | | Not in MQL5 | No tick-size rounding function. NormalizeDouble rounds to a count of decimal digits (0 to 8), not to a multiple of the tick size. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/roundtoticksize.htm) | `Instrument.MasterInstrument.RoundToTickSize` | Equivalent, with a caveat | Called on the instrument object; page says it rounds up to a tick multiple, where Lipi rounds to nearest. A separate RoundDownToTickSize exists. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_math.round_to_mintick) | `math.round_to_mintick` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Round) | `Round, TickSize` | Built from several Lipi constructs | No single function: divide by TickSize(), Round to 0 digits, multiply back by TickSize(). Lipi math.round\_to\_mintick does this in one call. |

## Smaller or larger of values

The smallest of the numbers you pass.

In Lipi: `math.min`, `math.max`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathmax) | `MathMin, MathMax` | Equivalent, with a caveat | Exactly two arguments; nest calls to compare more values, where Lipi accepts any number. |
| [MQL5](https://www.mql5.com/en/docs/math/mathmin) | `MathMin, MathMax` | Equivalent, with a caveat | Exactly two arguments; nest calls for more values. Integer arguments keep an integer result type. Numbers and types: Mixed argument types are cast to the larger type, and the result has that type. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | `Math.Min, Math.Max` | Equivalent, with a caveat | Exactly two arguments; Lipi accepts any number of values. Nest the calls to compare more. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.min, math.max` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Max) | `Min, Max` | Equivalent, with a caveat | Exactly two arguments; Lipi math.min and math.max take any number. Neither looks back over bars (Lowest and Highest do). |

## Powers and roots

`base` raised to the power of `exponent`.

In Lipi: `math.pow`, `math.sqrt`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathpow) | `MathPow, MathSqrt` | Exact | |
| [MQL5](https://www.mql5.com/en/docs/math/mathpow) | `MathPow, MathSqrt` | Exact | |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | `Math.Pow, Math.Sqrt` | Equivalent, with a caveat | Math.Pow returns infinity for a zero base with a negative exponent; Lipi math.pow returns na there, changing later comparisons. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.pow, math.sqrt` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Power) | `Power, Sqrt, Sqr` | Equivalent, with a caveat | Power and Sqrt map to math.pow and math.sqrt; Sqr (square) has no Lipi function, use math.pow(x, 2). |

## Exponent and logarithms

Euler's number raised to the power of `number`.

In Lipi: `math.exp`, `math.log`, `math.log10`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathlog) | `MathExp, MathLog, MathLog10` | Equivalent, with a caveat | Invalid input gives NaN, and MathLog(0) gives INF, where Lipi's log10 gives na. Warm-up and missing values: out-of-domain input yields NaN or INF, not na. |
| [MQL5](https://www.mql5.com/en/docs/math/mathlog) | `MathExp, MathLog, MathLog10` | Equivalent, with a caveat | MathLog(0) returns infinity and negatives give NaN; Lipi math.log(0) and negatives return na, so later comparisons on the result differ. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | `Math.Exp, Math.Log, Math.Log10` | Equivalent, with a caveat | Math.Log(0) returns negative infinity; Lipi math.log(0) returns na, so later comparisons on the result differ. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.exp, math.log, math.log10` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Lg) | `Exp, Log, Lg` | Equivalent, with a caveat | Log is the natural logarithm and Lg is base 10, so Lg maps to math.log10, not math.log. |

## Trigonometry

The sine of `angle`, where the angle is in radians.

In Lipi: `math.sin`, `math.cos`, `math.tan`, `math.asin`, `math.acos`, `math.atan`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathsin#MathSin) | `MathSin, MathCos, MathTan, MathArcsin, MathArccos, MathArctan` | Exact | |
| [MQL5](https://www.mql5.com/en/docs/math/mathsin) | `MathSin, MathCos, MathTan, MathArcsin, MathArccos, MathArctan` | Exact | |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | `Math.Sin, Math.Cos, Math.Tan, Math.Asin, Math.Acos, Math.Atan` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.sin, math.cos, math.tan, math.asin, math.acos, math.atan` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Sin) | `Sin, Cos, Tan, ASin, ACos, ATan` | Exact | |

## Degrees and radians

Converts an angle in radians to the same angle in degrees.

In Lipi: `math.todegrees`, `math.toradians`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math) | | Not in MQL4 | No degree/radian converters in the math group; multiply by the pi/180 factor yourself. |
| [MQL5](https://www.mql5.com/en/docs/math) | | Not in MQL5 | The math index has no degree or radian conversion function; multiply by 180 over pi yourself. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math) | | Not in NinjaScript | System.Math has no degree or radian converters; multiply by 180/Math.PI, or its inverse, by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.todegrees, math.toradians` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/ATan) | | Not in thinkScript | No degree/radian conversion function in the math section; docs multiply by 180 and divide by Double.Pi by hand. |

## Sign of a number

The sign of `number`: -1 for a negative number and 1 for a positive one.

In Lipi: `math.sign`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math) | | Not in MQL4 | No sign function in the math group; compare the value to zero. |
| [MQL5](https://www.mql5.com/en/docs/math) | | Not in MQL5 | No sign function in the math index; use a comparison expression instead. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.math.sign) | `Math.Sign` | Equivalent, with a caveat | Returns an int (-1, 0 or 1), while Lipi returns a float; it throws on NaN. Numbers and types: int result instead of float. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_math.sign) | `math.sign` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Sign) | `Sign` | Equivalent, with a caveat | Returns 1, 0 or -1, so zero gives 0; Lipi's reference states only -1 and 1, so check how it treats zero. |

## Random number

Gives your script a random float, bounded below by `min` and above by `max`.

In Lipi: `math.random`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math/mathrand) | `MathRand, MathSrand` | Looks alike, behaves differently | Returns an integer 0 to 32767, not a float in a range you choose; scale it yourself. Call MathSrand first to set the seed. State and side effects: generator state is seeded with MathSrand; a fixed seed repeats the sequence. |
| [MQL5](https://www.mql5.com/en/docs/math/mathrand) | `MathRand, MathSrand` | Looks alike, behaves differently | Returns an integer from 0 to 32767, not a float between two bounds. Seed with MathSrand before the first call and scale the result yourself. Numbers and types: Integer result 0 to 32767 instead of a float within min and max. State and side effects: The generator must be seeded with MathSrand first; Lipi has no seed argument. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.random.nextdouble) | `Random.NextDouble()` | Equivalent, with a caveat | An instance method on a Random object; returns 0.0 up to but excluding 1.0. Scale to min and max by hand. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_math.random) | `math.random` | Equivalent, with a caveat | Pine takes an optional seed for repeatable sequences; Lipi has none. Pine's reference excludes the lower bound, Lipi's docs include it. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Random) | `Random` | Equivalent, with a caveat | Takes no arguments and returns a value from 0.0 up to, not including, 1.0; scale it yourself to match math.random(min, max). |

## Average and sum of values

The arithmetic mean of the numbers you pass: their sum divided by how many there are.

In Lipi: `math.avg`, `math.sum`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/math) | | Not in MQL4 | No average or multi-value sum in the math group; MathMax and MathMin take two values only. |
| [MQL5](https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/array_stat/mathmean) | `MathMean, vector::Sum` | Equivalent, with a caveat | MathMean averages an array, not a list of arguments. There is no per-bar windowed sum; vector::Sum totals a whole vector you fill first. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable) | `Enumerable.Average() and Enumerable.Sum() (System.Linq)` | Equivalent, with a caveat | Apply to an array or list, not to separate arguments; needs using System.Linq. Average and Sum are separate calls. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `math.avg, math.sum` | Equivalent, with a caveat | Pine math.sum ignores na values; Lipi returns na on bars where the current source is na and skips na inside the window. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Average) | `Average, Sum` | Looks alike, behaves differently | Average is a moving window like ta.sma, not Lipi math.avg (mean of its arguments). Sum is a window sum and matches math.sum. History indexing: Average looks back over length bars; Lipi math.avg averages only its own arguments on the current bar. |

## Number to text

Renders a value as a string.

In Lipi: `str.tostring`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/convert/doubletostring) | `DoubleToString, IntegerToString` | Equivalent, with a caveat | One function per type; DoubleToString defaults to 8 decimals where Lipi trims to 4. No na or bool rendering is documented. Numbers and types: decimals are set by the digits argument (0-16); negative values give scientific format. |
| [MQL5](https://www.mql5.com/en/docs/convert/doubletostring) | `DoubleToString, IntegerToString` | Equivalent, with a caveat | Fixed decimal places (default 8; negative digits give scientific form). Separate IntegerToString for integers; no bool or na handling. Numbers and types: Digits 0 to 16 are kept as fixed places; Lipi rounds to 4 places and trims trailing zeros. |
| [NinjaScript](https://ninjatrader.com/support/helpGuides/nt8/basic_syntax.htm) | `ToString()` | Equivalent, with a caveat | No default four-decimal rounding: full precision prints. Bool prints True or False. Custom patterns go in as a format string. Numbers and types: Lipi rounds floats to four decimals by default; C# does not. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.tostring) | `str.tostring` | Equivalent, with a caveat | Pine renders na as "NaN"; Lipi renders "NA". Lipi's unformatted float rounds to 4 decimals; Pine's reference states no such default. Warm-up and missing values: A na value becomes the text "NaN" in Pine and "NA" in Lipi, so string comparisons on it differ. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AsText) | `AsText` | Looks alike, behaves differently | AsText defaults to 2 decimals; Lipi str.tostring rounds to 4 decimals. Concat and the + operator convert doubles with 4 decimals. Numbers and types: Decimal places come from a NumberFormat constant, not a format string such as Lipi's "#.####". |

## Text to number

Reads a number out of a string.

In Lipi: `str.tonumber`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/convert/stringtodouble) | `StringToDouble, StringToInteger` | Equivalent, with a caveat | Two functions by result type (double, long); Lipi always returns float. Behaviour on unparsable text is not documented. Numbers and types: StringToInteger returns long, not float. |
| [MQL5](https://www.mql5.com/en/docs/convert/stringtodouble) | `StringToDouble, StringToInteger` | Equivalent, with a caveat | Two functions by result type (double or long); Lipi always returns a float. The page does not state behaviour on invalid text. Numbers and types: StringToInteger returns long; Lipi returns float for every input. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse) | `double.TryParse / double.Parse` | Equivalent, with a caveat | TryParse reports success through a bool return and an out parameter instead of giving na on bad text. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.tonumber) | `str.tonumber` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/Data-Conversion) | | Not in thinkScript | No text-to-number function: the conversion table shows String accepting only Symbol, and no function in the reference parses text. |

## Length of text

Gives the length of a string as an int.

In Lipi: `str.length`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringlen) | `StringLen` | Equivalent, with a caveat | Counts symbols of a Unicode string; Lipi counts UTF-8 bytes, so non-ASCII text gives different numbers. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringlen) | `StringLen` | Equivalent, with a caveat | Counts symbols without the terminating zero. Lipi counts UTF-8 bytes, so non-ASCII text can give different results. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string.length) | `string.Length` | Equivalent, with a caveat | A property, not a call; it counts Char objects (UTF-16 units) where Lipi counts UTF-8 bytes, so non-ASCII text can differ. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.length) | `str.length` | Equivalent, with a caveat | Pine's reference counts characters; Lipi counts UTF-8 bytes, so text outside ASCII gives a larger Lipi length. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Data-Types/String) | | Not in thinkScript | No string length function; the String type page describes only text constants in double quotes. |

## Upper and lower case

Converts a string to upper case; the other half of the pair with str.lower.

In Lipi: `str.upper`, `str.lower`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringtoupper) | `StringToUpper, StringToLower` | Looks alike, behaves differently | Changes the variable in place and returns a success bool, not the converted text; do not use the result as the string. State and side effects: the string argument is \[in]\[out] and is modified by the call. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringtoupper) | `StringToUpper, StringToLower` | Looks alike, behaves differently | Changes the variable in place and returns a success flag, not the new string. Code like s = StringToUpper(s) is wrong here. State and side effects: Mutates its argument by reference; Lipi returns a new string and leaves the source unchanged. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string) | `ToUpper(), ToLower()` | Equivalent, with a caveat | ToUpper() and ToLower() use the current culture's casing rules; Lipi's str.upper and str.lower do not depend on culture. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `str.upper, str.lower` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No upper or lower case functions in the reference; text tools are limited to +, Concat and AsText. |

## Find text

Tests whether one string occurs inside another.

In Lipi: `str.contains`, `str.pos`, `str.startswith`, `str.endswith`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringfind#StringFind) | `StringFind` | Equivalent, with a caveat | Returns the start position or -1, like str.pos. Contains is a test for >= 0; starts-with and ends-with have no function. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringfind) | `StringFind` | Equivalent, with a caveat | One function returns a 0-based start position or -1. Contains, startswith and endswith are tests on that result or on StringSubstr. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings) | `Contains, IndexOf, StartsWith, EndsWith` | Equivalent, with a caveat | IndexOf returns a character index where Lipi counts bytes. StartsWith and EndsWith with a string argument are culture-sensitive by default. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `str.contains, str.pos, str.startswith, str.endswith` | Equivalent, with a caveat | str.pos returns na when absent, Lipi returns -1 (byte offsets). Pine names the second parameter str in startswith and endswith; Lipi uses prefix and suffix. Warm-up and missing values: Not-found is na in Pine and -1 in Lipi, so a na() test on the result never fires in Lipi. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetSymbolPart) | | Not in thinkScript | No contains, position, starts-with or ends-with function; the docs only show whole-string == comparison. |

## Part of a text

Cuts a piece out of a string.

In Lipi: `str.substring`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringsubstr) | `StringSubstr` | Looks alike, behaves differently | Third argument is a length, not an end index; a length of 0 or less runs to the end of the string. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringsubstr) | `StringSubstr` | Looks alike, behaves differently | The third argument is a length, not an end index; -1 or omitted runs to the end. Lipi's second bound is an exclusive end position. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string) | `Substring` | Looks alike, behaves differently | Second argument is a length, not an exclusive end index as in Lipi. .NET counts UTF-16 code units; Lipi counts whole characters. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.substring) | `str.substring` | Equivalent, with a caveat | Same 0-based, start-inclusive, end-exclusive cut with optional end. Pine's parameters are begin\_pos and end\_pos; Lipi's are start and end. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No substring or slicing function; strings can only be built (Concat, +) and compared. |

## Replace text

Substitutes one piece of text for another inside a string.

In Lipi: `str.replace`, `str.replace_all`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringreplace#StringReplace) | `StringReplace` | Looks alike, behaves differently | Edits the string in place, replaces every match, and returns the replacement count (-1 on error), not the new text. State and side effects: the str argument is \[in]\[out] and is modified. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringreplace) | `StringReplace` | Looks alike, behaves differently | Edits the variable in place, replaces every match and returns the replacement count (-1 on error). There is no maximum-count argument. State and side effects: Mutates its argument and returns a count, not the new string. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string) | `Replace` | Equivalent, with a caveat | Replaces every occurrence and has no count argument, so it matches Lipi's replace\_all, not the counted replace. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `str.replace, str.replace_all` | Looks alike, behaves differently | Pine str.replace changes only the single occurrence numbered by occurrence (0-based, default first). Lipi's str.replace changes all unless count limits it. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No text replacement function in the reference. |

## Split text

Splits `string` wherever `separator` occurs and returns the pieces as an array of strings.

In Lipi: `str.split`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringsplit#StringSplit) | `StringSplit` | Equivalent, with a caveat | Separator is one character code (ushort), pieces fill an output array, and the return value is the piece count. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringsplit) | `StringSplit` | Equivalent, with a caveat | The separator is one character code, not a string. Pieces go into an output array and the call returns their count. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string) | `Split` | Equivalent, with a caveat | Returns string\[]. The separator is a char or an array of strings plus an options value, not one plain string argument. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.split) | `str.split` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No split function, and no array type to return pieces in. |

## Trim spaces

Removes whitespace from around a string and hands back the result.

In Lipi: `str.trim`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringtrimleft) | `StringTrimLeft, StringTrimRight` | Equivalent, with a caveat | Two functions, one per side; the page says the string is modified in place and a copy is returned. Call both to trim both ends. State and side effects: The page says the string argument is modified in place as well as returned. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringtrimleft) | `StringTrimLeft, StringTrimRight` | Equivalent, with a caveat | Two in-place calls, one per side, each returning the number of cut characters. They cut line feeds, spaces and tabs. State and side effects: Mutates the variable passed in instead of returning a new string. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.string) | `Trim()` | Exact | |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.trim) | `str.trim` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No whitespace trimming function in the reference. |

## Repeat text

Produces a string made of repeated copies of another, with the option of something between the copies.

In Lipi: `str.repeat`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringinit) | `StringInit` | Equivalent, with a caveat | Fills a string with one repeated character in place; cannot repeat a multi-character text or add a separator. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringinit) | `StringInit` | Equivalent, with a caveat | Fills a variable with one repeated character code to a set length. It cannot repeat a longer string or add a separator. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable) | `string.Concat(Enumerable.Repeat(text, count))` | Equivalent, with a caveat | No String method repeats text. Combine Enumerable.Repeat with string.Concat or string.Join; a separator needs Join. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.repeat) | `str.repeat` | Equivalent, with a caveat | Same behaviour; the count parameter is named repeat in Pine and count in Lipi, which matters for named arguments. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No text repeat function in the reference. |

## Match a pattern

Returns the first part of `source` that matches the regular expression `pattern`.

In Lipi: `str.match`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings) | | Not in MQL4 | No regular-expression function in the string group; search with StringFind and cut with StringSubstr. |
| [MQL5](https://www.mql5.com/en/docs/strings) | | Not in MQL5 | The string function list has no regular-expression function; pattern matching needs manual string handling. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.match) | `Regex.Match(input, pattern)` | Equivalent, with a caveat | Returns the first match as a Match object, not a string; read its Value property. Pattern syntax is .NET regex, not RE2. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/#fun_str.match) | `str.match` | Equivalent, with a caveat | Parameter is regex in Pine, pattern in Lipi. Lipi patterns use RE2 (no lookaround or backreferences); Pine's reference names no dialect. |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others) | | Not in thinkScript | No regular-expression or pattern matching function in the reference. |

## Join texts

Joining two pieces of text into one.

In Lipi: `+`.

| Language | Construct | Relation | Note |
| - | - | - | - |
| [MQL4](https://docs.mql4.com/strings/stringconcatenate) | `+ operator, StringConcatenate` | Equivalent, with a caveat | In MQL4 + joins a string and a number by converting the number; Lipi needs str.tostring first. StringConcatenate joins many values in one call. |
| [MQL5](https://www.mql5.com/en/docs/strings/stringadd) | `+` | Equivalent, with a caveat | MQL5 casts the non-string operand of + to string automatically; Lipi rejects string + number, so numbers must be wrapped in str.tostring. |
| [NinjaScript](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/addition-operator#string-concatenation) | `+` | Equivalent, with a caveat | C# + converts a non-text operand to text; Lipi's + joins text only, so wrap numbers in str.tostring. |
| [Pine Script](https://www.tradingview.com/pine-script-reference/v6/) | `+` | Exact | |
| [thinkScript](https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Concat) | `+, Concat` | Equivalent, with a caveat | Concat joins exactly two values, so nest calls for more; + does the same inline. Non-text values are converted first, doubles with 4 decimals. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.