Columnal Documentation: Table of Contents

conversion functions

from textfrom text toto textextract numberextract number or none
from text(text)value Type: For any types t where Readable t(Text) -> t

Converts a value from text.

This function works for any readable type (the only non-readable types are function types). If the intended type cannot be inferred automatically, you may need to use the from text to(..) function to specify the type .

Some notes for specific types:

  • For boolean values, lower-case and upper-case are allowed in the names.
  • Dates are read using a variety of formats. Be careful with the DD-MM-YY formats and similar as they are ambiguous against MM-DD-YY. If this is an issue, use the date from string function to specify a format.
  • Numbers must use dot as the decimal separator, commas are not supported.
  • If you want to get a Text out of from text, it must be in quotes.
ExamplesClick an example to insert it
from text("65") > 64true
from text("TRUE") | falsetrue
as type(type{Date}, from text("21 March 2004"))date from ymd(2004{year}, 3{month}, 21{day})
as type(type{[(a: Boolean, b: Number{m})]}, from text("[(a:True, b:0), (a:FALSE, b:-1.6)]"))[(a:true, b:0{m}), (a:false, b:-1.6{m})]
from text to(value type, text)value Type: For any types t where Readable t(@apply Type(t), Text) -> t

Converts a value from text, specifying the target type.

See from text(..) for more details.

ExamplesClick an example to insert it
from text to(type{Date}, "21 March 2004")date from ymd(2004{year}, 3{month}, 21{day})
from text to(type{[(a:Boolean, b:Number{m})]}, "[(a:True, b:0), (a:FALSE, b:-1.6)]")[(a:true, b:0{m}), (a:false, b:-1.6{m})]
to text(value)text Type: For any types t where Showable t(t) -> Text

Converts a value to text.

ExamplesClick an example to insert it
to text(true)"true"
to text(65{m})"65"
extract number(text)number Type: (Text) -> Number

Extracts a number from the given text. If there is no number, or two numbers, gives an error.

The difference between this function and from text(..) is that this function will accept and ignore extra text around the number, and deal with comma separators. So whereas from text will give an error on "P65n" because it's not solely a number, this extract number function will return 65.

The function assumes that commas are thousand separators, and dot is the decimal separator. If you need to convert continental European style numbers where the opposite is true, use the replace many function as shown in the last example.

ExamplesClick an example to insert it
extract number("-34.20m")-34.2
extract number("£17,000,000")17000000
extract number("The 6 cats")6
extract number("2 and 2 makes 4")error
extract number("Two")error
extract number(replace many([(find: ".", replace: ","), (find: ",", replace: ".")], "10.449,99"))10449.99Swaps dots and commas
extract number or none(text)number Type: (Text) -> @apply Optional(Number)

Extracts a number from the given text. If there is no number, or two numbers, gives back None.

The difference between this function and extract number(..) is that this function gives back an Optional(Number), so rather than giving an error when there is no number, it gives back None. Successfully extracted numbers are wrapped in the opposing Is constructor; see the optional guide.

ExamplesClick an example to insert it
extract number or none("-34.20m")Optional\Is(-34.2)
extract number or none("£17,000,000")Optional\Is(17000000)
extract number or none("The 6 cats")Optional\Is(6)
extract number or none("2 and 2 makes 4")Optional\None
extract number or none("Two")Optional\None