Striping Whitespace #67
-
Hello guys, I'm trying do a simple bit of code that removes trailing whitespace from text and then prints but i can't get it to work. fav_language = "Motoko " fav_language = fav_language.rstip() import Debug "mo:base/Debug"; actor {
}; Error [08:24:58] base library version moc-0.6.24 [08:25:30] Error in file Main.mo:9:26 field stripEnd does not exist in type Text [08:25:30] cannot deploy: syntax errorMotoko Playground link: https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=1958262068 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The syntax should not be Here is the code:
|
Beta Was this translation helpful? Give feedback.
-
Thank you that clears up a lot for me! |
Beta Was this translation helpful? Give feedback.
The syntax should not be
favourite_language.stripEnd()
It should be
Text.stripEnd(favourite_language, #text " ")
stripEnd is a function in Text library so the syntax is Text.stripEnd()
Inside the stripEnd() we got 2 variables:
func stripEnd(t : [Text], p : [Pattern]) : ?[Text]
There are t is your Text, and p is the pattern
Pattern = {#char : Char; #text : [Text]; #predicate : (Char -> Bool)}
In this case, we want to delete the white space in the text so we use
#text " "
Here is the code: