{{fbdoc item="title" value="LEFT"}}---- Returns the leftmost substring of a string {{fbdoc item="syntax"}}## [[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Left** ( [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]], [[KeyPgByval|byval]] //n// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgAs|as]] [[KeyPgString|string]] [[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Left** ( [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]], [[KeyPgByval|byval]] //n// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgAs|as]] [[KeyPgWstring|wstring]] ## {{fbdoc item="usage"}}## //result// = **Left**[$]( //str//, //n// ) ## {{fbdoc item="param"}} ##//str//## The source string. ##//n//## The number of characters to return from the source string. {{fbdoc item="ret"}} Returns the leftmost substring from ##//str//##. {{fbdoc item="desc"}} Returns the leftmost ##//n//## characters starting from the left (beginning) of ##//str//##. If ##//str//## is empty, then the null string (##"####"##) is returned. If ##//n// <= 0## then the null string (##"####"##) is returned. If ##//n// > len(//str//)## then the entire source string is returned. {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/strings/left.bas"}}%%(freebasic) dim text as string = "hello world" print left(text, 5) %% will produce the output: %%hello %% An Unicode example: << dim text as wstring*20 text = "Привет, мир!" print left(text, 6) 'displays "Привет" <<::c:: {{fbdoc item="target"}} - DOS does not support the wide-character string version of **##Left##**. {{fbdoc item="lang"}} - The string type suffix "$" is required in the //[[CompilerOptlang|-lang qb]]// dialect. - The string type suffix "$" is optional in the //[[CompilerOptlang|-lang fblite]]// dialect. - The string type suffix "$" is ignored in the //[[CompilerOptlang|-lang fb]]// dialect, warn only with the //[[CompilerOptw|-w suffix]]// compile option (or //[[CompilerOptw|-w pedantic]]// compile option). {{fbdoc item="diff"}} - QB does not support Unicode. {{fbdoc item="see"}} - ##[[KeyPgRight|Right]]## - ##[[KeyPgMidfunction|Mid (Function)]]## {{fbdoc item="back" value="CatPgString|String Functions"}}