Reference > Functions > String
LTrim
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
LTrim (Left Trim) String Function
Use the LTrim
function to remove leading spaces from a string expression.
Syntax
db.fx.LTrim({expression})
Arguments
- expression
- – The value to remove leading spaces from.
Returns
string or string?
(depending on the nullability of `expression`)
Examples
Select Statement
Select the a person's last name, with leading spaces removed.
IEnumerable<string> result = db.SelectMany(
db.fx.LTrim(dbo.Person.LastName)
)
.From(dbo.Person)
.Execute();
Where Clause
Select persons where their last name starts with one or more spaces.
IEnumerable<Person> result = db.SelectMany<Person>()
.From(dbo.Person)
.Where(db.fx.LTrim(dbo.Person.LastName) != dbo.Person.LastName)
.Execute();
Order By Clause
Select a list of persons, ordered by their last name with leading spaces removed.
IEnumerable<Person> result = db.SelectMany<Person>()
.From(dbo.Person)
.OrderBy(db.fx.LTrim(dbo.Person.LastName))
.Execute();
Group By Clause
Select a list of address values grouped by address type and the value of the city field with leading spaces removed.
IEnumerable<dynamic> values = db.SelectMany(
dbo.Address.AddressType,
db.fx.LTrim(dbo.Address.City).As("city")
)
.From(dbo.Address)
.GroupBy(
dbo.Address.AddressType,
db.fx.LTrim(dbo.Address.City)
)
.Execute();
Having Clause
Select a list of address data, grouped by address type and city where the value of city with leading spaces removed is "Chicago".
IEnumerable<dynamic> addresses = db.SelectMany(
db.fx.Count().As("count"),
dbo.Address.AddressType
)
.From(dbo.Address)
.GroupBy(
dbo.Address.AddressType,
dbo.Address.City
)
.Having(
db.fx.LTrim(dbo.Address.City) == "Chicago"
)
.Execute();