Equinox Online Help - Language Reference - A to Z

Home

Mid [Function]

Applies to
SyntaxMid(StringExpression, StartExpression [, LengthExpression])
Action[Function] Returns a segment of a string.
ScopeUsable anywhere.
Notes

This function returns 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 in the segment. 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).

This function 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 statement, to assign a value to part of a string. This feature is described separately, in the following section

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

This example assigns part of the string txt to the field address4, starting from the fiftieth character.

address4 = Mid(txt, 50)

The next example assigns either four or six characters from the field PostCode to streetcode, depending on the value of areacode.

Number length

...

If areacode = "A" Then length = 4 Else length = 6
streetcode = Mid(PostCode, 3, length)