left(string,n)
| Function group | Execute on client | Platform(s) |
|---|---|---|
| String | YES | All |
left(string,n)
left(string,n[,mode=kLeftRightCount])
Returns the substring comprising the first n characters of the string.
Calculate lResult as left('Raining',4)
# returns 'Rain'
Returns the first n characters of the string. If mode is kLeftRightSearchExclude or kLeftRightSearchInclude, n is a search string and the result ends before or after its first occurrence or is #NULL.
The optional mode parameter takes one of the String search modes constants, and says how n is used:
In the search modes:
left('File.Field','.',kLeftRightSearchExclude)
; returns 'File'
left('File.Field','.',kLeftRightSearchInclude)
; returns 'File.'
left('Lib.File.Field','.',kLeftRightSearchExclude)
; returns 'Lib' (the first occurrence)
left('0123456789','45',kLeftRightSearchExclude)
; returns '0123'
left('.Field','.',kLeftRightSearchExclude)
; returns '' (the match is at the start)
left('12345','6',kLeftRightSearchExclude)
; returns #NULL (not found)
left('0123456789',5)
; returns '01234' (a character count, as before)
#NULL is not the same as an empty string, and functions treat it differently: con() and len() treat it as empty, while others such as upp() return #NULL. Test the result with isnull() when the search string might be missing; see example.
Calculate lFileNamePart as left(lFieldName,'.',kLeft)
If isnull(lFileNamePart)
Calculate lFileNamePart as lFieldName
End If