- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Get started with Canton Network App Dev Quickstart
- Using the JSON Ledger API
- Get started with smart contract development
- Basic contracts
- Test templates using Daml scripts
- Build the Daml Archive (.dar) file
- Data types
- Transform contracts using choices
- Add constraints to a contract
- Parties and authority
- Compose choices
- Handle exceptions
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Application development
- Getting started
- Development how-tos
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- Overview: Template Structure
- Reference: Templates
- Reference: Choices
- Reference: Updates
- Reference: Data Types
- Reference: Built-in Functions
- Reference: Expressions
- Reference: Functions
- Reference: Daml File Structure
- Reference: Daml Packages
- Reference: Contract Keys
- Reference: Interfaces
- Reference: Exceptions (Deprecated)
- Daml standard library
- DA.Action.State.Class
- DA.Action.State
- DA.Action
- DA.Assert
- DA.Bifunctor
- DA.Crypto.Text
- DA.Date
- DA.Either
- DA.Exception
- DA.Fail
- DA.Foldable
- DA.Functor
- DA.Internal.Interface.AnyView.Types
- DA.Internal.Interface.AnyView
- DA.List.BuiltinOrder
- DA.List.Total
- DA.List
- DA.Logic
- DA.Map
- DA.Math
- DA.Monoid
- DA.NonEmpty.Types
- DA.NonEmpty
- DA.Numeric
- DA.Optional
- DA.Record
- DA.Semigroup
- DA.Set
- DA.Stack
- DA.Text
- DA.TextMap
- DA.Time
- DA.Traversable
- DA.Tuple
- DA.Validation
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Daml Script
- Smart contract upgrading reference
- Glossary of concepts
DA.Text¶
Functions for working with Text.
Functions¶
- isNotEmpty
-
Test for non-emptiness.
- replace
: Text -> Text -> Text -> Text
Replace a subsequence everywhere it occurs. The first argument must not be empty.
- lines
-
Breaks a
Textvalue up into a list ofText’s at newline symbols. The resulting texts do not contain newline symbols.
- words
-
Breaks a ‘Text’ up into a list of words, delimited by symbols representing white space.
- linesBy
: (Text -> Bool) -> Text -> [Text]
A variant of
lineswith a custom test. In particular, if there is a trailing separator it will be discarded.
- wordsBy
: (Text -> Bool) -> Text -> [Text]
A variant of
wordswith a custom test. In particular, adjacent separators are discarded, as are leading or trailing separators.
- intercalate
-
intercalateinserts the text argumenttin between the items intsand concatenates the result.
- dropPrefix
-
dropPrefixdrops the given prefix from the argument. It returns the original text if the text doesn’t start with the given prefix.
- dropSuffix
-
Drops the given suffix from the argument. It returns the original text if the text doesn’t end with the given suffix. Examples:
dropSuffix "!" "Hello World!" == "Hello World" dropSuffix "!" "Hello World!!" == "Hello World!" dropSuffix "!" "Hello World." == "Hello World."
- stripSuffix
: Text -> Text -> Optional Text
Return the prefix of the second text if its suffix matches the entire first text. Examples:
stripSuffix "bar" "foobar" == Some "foo" stripSuffix "" "baz" == Some "baz" stripSuffix "foo" "quux" == None
- stripPrefix
: Text -> Text -> Optional Text
The
stripPrefixfunction drops the given prefix from the argument text. It returnsNoneif the text did not start with the prefix.
- isPrefixOf
-
The
isPrefixOffunction takes two text arguments and returnsTrueif and only if the first is a prefix of the second.
- isSuffixOf
-
The
isSuffixOffunction takes two text arguments and returnsTrueif and only if the first is a suffix of the second.
- isInfixOf
-
The
isInfixOffunction takes two text arguments and returnsTrueif and only if the first is contained, wholly and intact, anywhere within the second.
- takeWhile
: (Text -> Bool) -> Text -> Text
The function
takeWhile, applied to a predicatepand a text, returns the longest prefix (possibly empty) of symbols that satisfyp.
- takeWhileEnd
: (Text -> Bool) -> Text -> Text
The function ‘takeWhileEnd’, applied to a predicate
pand a ‘Text’, returns the longest suffix (possibly empty) of elements that satisfyp.
- dropWhile
: (Text -> Bool) -> Text -> Text
dropWhile p treturns the suffix remaining aftertakeWhile p t.
- dropWhileEnd
: (Text -> Bool) -> Text -> Text
dropWhileEnd p treturns the prefix remaining after dropping symbols that satisfy the predicatepfrom the end oft.
- splitOn
-
Break a text into pieces separated by the first text argument (which cannot be empty), consuming the delimiter.
- splitAt
-
Split a text before a given position so that for
0 <= n <= length t,length (fst (splitAt n t)) == n.
- take
-
take n, applied to a textt, returns the prefix oftof lengthn, ortitself ifnis greater than the length oft.
- drop
-
drop n, applied to a textt, returns the suffix oftafter the firstncharacters, or the emptyTextifnis greater than the length oft.
- substring
-
Compute the sequence of symbols of length
lin the argument text starting ats.
- isPred
: (Text -> Bool) -> Text -> Bool
isPred f treturnsTrueiftis not empty andfisTruefor all symbols int.
- isAlphaNum
-
isAlphaNum tisTrueiftis not empty and consists only of alphanumeric symbols.
- parseNumeric
: NumericScale n => Text -> Optional (Numeric n)
Attempt to parse a
Numericvalue from a givenText. To getSomevalue, the text must follow the regex(-|\+)?[0-9]+(\.[0-9]+)?In particular, the shorthands".12"and"12."do not work, but the value can be prefixed with+. Leading and trailing zeros are fine, however spaces are not. Examples:parseNumeric "3.14" == Some 3.14 parseNumeric "+12.0" == Some 12
- parseDecimal
-
Attempt to parse a
Decimalvalue from a givenText. To getSomevalue, the text must follow the regex(-|\+)?[0-9]+(\.[0-9]+)?In particular, the shorthands".12"and"12."do not work, but the value can be prefixed with+. Leading and trailing zeros are fine, however spaces are not. Examples:parseDecimal "3.14" == Some 3.14 parseDecimal "+12.0" == Some 12
- sha256
-
Computes the SHA256 hash of the UTF8 bytes of the
Text, and returns it in its hex-encoded form. The hex encoding uses lowercase letters.This function will crash at runtime if you compile Daml to Daml-LF < 1.2.
- toCodePoints
-
Convert a
Textinto a sequence of unicode code points.
- fromCodePoints
-
Convert a sequence of unicode code points into a
Text. Raises an exception if any of the code points is invalid.
- asciiToLower
-
Convert the uppercase ASCII characters of a
Textto lowercase; all other characters remain unchanged.
- asciiToUpper
-
Convert the lowercase ASCII characters of a
Textto uppercase; all other characters remain unchanged.