strip()#
relationalai.std.strings
#strip(string: str|Producer) -> Expression
Removes leading and trailing whitespace from a string. Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
string | str or Producer | The string to remove leading and trailing whitespace from. |
Returns#
An Expression
object.
Example#
#import relationalai as rai
from relationalai.std import alias
from relationalai.std.strings import strip
# =====
# SETUP
# =====
# Create a model named "people" with a Person type.
model = rai.Model("people")
Person = model.Type("Person")
# Add some people to the model.
with model.rule():
Person.add(id=1).set(raw_name=" Alice")
Person.add(id=2).set(raw_name="Bob ")
# =======
# EXAMPLE
# =======
# Strip leading and trailing whitespace from the names.
with model.query() as select:
person = Person()
stripped_name = strip(person.raw_name)
response = select(
person.raw_name,
alias(stripped_name, "stripped_name"),
)
print(response.results)
# raw_name stripped_name
# 0 Alice Alice
# 1 Bob Bob