> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/string/left.md).

# Left

Extract the leftmost count characters from a string

## Method Signature

```
Left(string=[string], count=[integer])
```

### Arguments

| Argument | Type      | Required | Description                           | Default |
| -------- | --------- | -------- | ------------------------------------- | ------- |
| `string` | `string`  | `true`   | The string to extract from            |         |
| `count`  | `integer` | `true`   | The number of characters to retrieve. |         |

## Examples

### Using left() on a string

In this example we'll use left() to return part of a string.

[Run Example](https://try.boxlang.io/?code=eJwrL8osSfUvLSkoLdFQyElNA5JKIRmpCoWlmcnZCklF%2BeV5Cmn5FQpZpbkFqSkK%2BWWpRQolQPmcxKpKhZT8dCUdBUNLBU0FTWsuAAH0GPg%3D)

```java
writeOutput( left( "The quick brown fox jumped over the lazy dog", 19 ) );

```

Result: The quick brown fox

### Using left() with a negative count on a string

In this example we'll use a negative count to return part of a string.

[Run Example](https://try.boxlang.io/?code=eJwrL8osSfUvLSkoLdFQyElNA5JKIRmpCoWlmcnZCklF%2BeV5Cmn5FQpZpbkFqSkK%2BWWpRQolQPmcxKpKhZT8dCUdBV0jUwVNBU1rLgAbLBki)

```java
writeOutput( left( "The quick brown fox jumped over the lazy dog", -25 ) );

```

Result: The quick brown fox

### Using left() in a function

In this example we'll use left() in a function to help us to capitalize the first letter in a string.

[Run Example](https://try.boxlang.io/?code=eJxty7EKAjEQhOHaPMVUcgcqWFuKb3CFbS7uxYW4nptdEMV3NxY2Yjv%2FN2H2sXBCNWXJmFyS8VWQ4swWCz%2Bog9LNWen0RUZ3Q49nWCiZq8D3sTZXaLIOUbNfSKxuhsNxWGHbaI8llPP5Ty4kv2Pj689tF17hDaJGNLo%3D)

```java

public string function capitalize( required string text ) {
	return uCase( left( arguments.TEXT, 1 ) ) & right( arguments.TEXT, len( arguments.TEXT ) - 1 );
}

```

### Using left() to test values

In this example we'll use left() to test the first five characters of a request context variable.

```java
if( listFindNoCase( "super,great,coder,rulez", left( rc.ANSWER, 5 ) ) ) {
	writeOutput( "You are an awesome developer!" );
}

```

### Using left() as a member function

In this example we'll use left() as a member function inside a function to help us to capitalize the first letter in a string.

[Run Example](https://try.boxlang.io/?code=eJxlyzEOwjAMBdCZnOJPKBmIxMzMDTqwhuAGS8EU15YQiLtTBhbY3wuTHztXzKYsDaNLNb4KapnYSucHRSjdnJVOX2R0NyQ8w0rJXAVFm19IbM7D%2FjDkTqNFbJGy1zJTTFj%2FEuV2XsxflAVvPnUXXuENAPc0eg%3D%3D)

```java

public string function capitalize( required string text ) {
	return arguments.TEXT.left( 1 ).ucase() & arguments.TEXT.right( arguments.TEXT.len() - 1 );
}

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLKc0t0FDISU0r0VBQSkxKTlHSUTBW0FTQtFbQ11cACnClIKsISC1JLQIq0TUEq%2BECKQKJcQEA1EkSxg%3D%3D)

```java
dump( left( "abcd", 3 ) ); // abc
dump( left( "Peter", -1 ) );
 // Pete

```

## Related

* [Ascii](/boxlang-language/reference/built-in-functions/string/ascii.md)
* [CamelCase](/boxlang-language/reference/built-in-functions/string/camelcase.md)
* [Char](/boxlang-language/reference/built-in-functions/string/char.md)
* [CharsetDecode](/boxlang-language/reference/built-in-functions/string/charsetdecode.md)
* [CharsetEncode](/boxlang-language/reference/built-in-functions/string/charsetencode.md)
* [Compare](/boxlang-language/reference/built-in-functions/string/compare.md)
* [CompareNoCase](/boxlang-language/reference/built-in-functions/string/comparenocase.md)
* [Find](/boxlang-language/reference/built-in-functions/string/find.md)
* [FindNoCase](/boxlang-language/reference/built-in-functions/string/findnocase.md)
* [FindOneOf](/boxlang-language/reference/built-in-functions/string/findoneof.md)
* [Insert](/boxlang-language/reference/built-in-functions/string/insert.md)
* [JSStringFormat](/boxlang-language/reference/built-in-functions/string/jsstringformat.md)
* [Justify](/boxlang-language/reference/built-in-functions/string/justify.md)
* [KebabCase](/boxlang-language/reference/built-in-functions/string/kebabcase.md)
* [LCase](/boxlang-language/reference/built-in-functions/string/lcase.md)
* [ListReduce](/boxlang-language/reference/built-in-functions/string/listreduce.md)
* [LJustify](/boxlang-language/reference/built-in-functions/string/ljustify.md)
* [LTrim](/boxlang-language/reference/built-in-functions/string/ltrim.md)
* [Mid](/boxlang-language/reference/built-in-functions/string/mid.md)
* [ParagraphFormat](/boxlang-language/reference/built-in-functions/string/paragraphformat.md)
* [PascalCase](/boxlang-language/reference/built-in-functions/string/pascalcase.md)
* [QueryStringToStruct](/boxlang-language/reference/built-in-functions/string/querystringtostruct.md)
* [ReEscape](/boxlang-language/reference/built-in-functions/string/reescape.md)
* [ReFind](/boxlang-language/reference/built-in-functions/string/refind.md)
* [reFindNoCase](/boxlang-language/reference/built-in-functions/string/refindnocase.md)
* [ReMatch](/boxlang-language/reference/built-in-functions/string/rematch.md)
* [reMatchNoCase](/boxlang-language/reference/built-in-functions/string/rematchnocase.md)
* [RemoveChars](/boxlang-language/reference/built-in-functions/string/removechars.md)
* [RepeatString](/boxlang-language/reference/built-in-functions/string/repeatstring.md)
* [Replace](/boxlang-language/reference/built-in-functions/string/replace.md)
* [ReplaceList](/boxlang-language/reference/built-in-functions/string/replacelist.md)
* [ReplaceListNoCase](/boxlang-language/reference/built-in-functions/string/replacelistnocase.md)
* [ReplaceNoCase](/boxlang-language/reference/built-in-functions/string/replacenocase.md)
* [ReReplace](/boxlang-language/reference/built-in-functions/string/rereplace.md)
* [reReplaceNoCase](/boxlang-language/reference/built-in-functions/string/rereplacenocase.md)
* [Reverse](/boxlang-language/reference/built-in-functions/string/reverse.md)
* [Right](/boxlang-language/reference/built-in-functions/string/right.md)
* [RJustify](/boxlang-language/reference/built-in-functions/string/rjustify.md)
* [RTrim](/boxlang-language/reference/built-in-functions/string/rtrim.md)
* [Slugify](/boxlang-language/reference/built-in-functions/string/slugify.md)
* [SnakeCase](/boxlang-language/reference/built-in-functions/string/snakecase.md)
* [SpanExcluding](/boxlang-language/reference/built-in-functions/string/spanexcluding.md)
* [SpanIncluding](/boxlang-language/reference/built-in-functions/string/spanincluding.md)
* [SQLPrettify](/boxlang-language/reference/built-in-functions/string/sqlprettify.md)
* [StringBind](/boxlang-language/reference/built-in-functions/string/stringbind.md)
* [StringEach](/boxlang-language/reference/built-in-functions/string/stringeach.md)
* [StringEndsWith](/boxlang-language/reference/built-in-functions/string/stringendswith.md)
* [StringEndsWithNoCase](/boxlang-language/reference/built-in-functions/string/stringendswithnocase.md)
* [StringEvery](/boxlang-language/reference/built-in-functions/string/stringevery.md)
* [StringFilter](/boxlang-language/reference/built-in-functions/string/stringfilter.md)
* [StringMap](/boxlang-language/reference/built-in-functions/string/stringmap.md)
* [StringReduce](/boxlang-language/reference/built-in-functions/string/stringreduce.md)
* [StringReduceRight](/boxlang-language/reference/built-in-functions/string/stringreduceright.md)
* [StringSome](/boxlang-language/reference/built-in-functions/string/stringsome.md)
* [StringSort](/boxlang-language/reference/built-in-functions/string/stringsort.md)
* [StringStartsWith](/boxlang-language/reference/built-in-functions/string/stringstartswith.md)
* [StringStartsWithNoCase](/boxlang-language/reference/built-in-functions/string/stringstartswithnocase.md)
* [StripCR](/boxlang-language/reference/built-in-functions/string/stripcr.md)
* [Trim](/boxlang-language/reference/built-in-functions/string/trim.md)
* [UCase](/boxlang-language/reference/built-in-functions/string/ucase.md)
* [UCFirst](/boxlang-language/reference/built-in-functions/string/ucfirst.md)
* [Val](/boxlang-language/reference/built-in-functions/string/val.md)
* [Wrap](/boxlang-language/reference/built-in-functions/string/wrap.md)
* [YesNoFormat](/boxlang-language/reference/built-in-functions/string/yesnoformat.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/string/left.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
