Equinox Online Help - Language Reference - A to Z

Home

Mid [Statement]

Applies to
SyntaxMid(StringExpression, StartExpression [, LengthExpression]) = NewExpression
Action[Statement] Assigns to a segment of a string.
ScopeUsable anywhere.
Notes

You can use this statement to assign a value to a segment of StringExpression. You use StartExpression to specify the position of the first character in the segment. You use LengthExpression to specify the number of characters that are replaced. If you omit it, it defaults to the length of StringExpression less the value of StartExpression. If LengthExpression is too big, it also reverts to this default (remember that trailing spaces in fields and workareas are ignored).

The segment is removed from StringItem. NewExpression is then inserted in its place, in a cut-and-paste style operation. You cannot insert characters beyond the maximum size of string (remember that trailing spaces in fields and workareas are ignored).

This statement works in a similar way as the [ ] notation, which you can use to return a single character from a string.

Note that you can also use Mid as a function, to return part of a string. This feature is described separately, in the previous section.

CategoryString handling
See Also ChrList, Chrs, Compare, Fill, IsNumber, Left_Function, Len, Match, Maxlen, Mid_Function, Remove, Replace, Right_Function], Search_SearchNext, SetLen, SetMaxLen, SortOrder, SubstituteData
Example

The following example changes the contents of the string txt from "statement" to "function".

string txt

txt="statement"
Right(txt, 4) = "" | state
Right(txt, 1) = "ion" | station
Left(txt, 3) = "ac" | action
txt[1] = "fi" | fiction
Mid(txt, 2, 1) = "un" | function