The standard library’s Data.String module provides many useful string-related functions. Here are some examples to give you a sense of the module.
In PureScript, string manipulation functions are typically found in the Data.String module. We import this module and alias it as S for brevity. We also import the Effect.Console module to use the log function for output.
Note that PureScript uses different function names for some operations compared to other languages:
contains is used instead of Contains
startsWith and endsWith are used instead of HasPrefix and HasSuffix
indexOf is used instead of Index
joinWith is used instead of Join
replicate is used instead of Repeat
replace and replaceAll are used instead of a single Replace function with a count parameter
Also, PureScript uses Pattern and Replacement wrappers for string patterns and replacements in some functions.
To run this program, you would typically compile it with the PureScript compiler and then run it with Node.js:
This demonstrates various string operations available in PureScript’s standard library.