Clearing part of a string – clear and trim

Let's say we want to delete all contents after "American" in the string s: "American politics". We can apply clear , to skip all characters before "politics", making the phrase clear skip s 8 Or we can let Red do the work with find, making the phrase clear find s " politics". In both cases, s becomes "American".

If you just want to remove spaces from a string, use trim. This method is very versatile, and can include a lot of refinements:

str: " No more war ! "trim/head str       ;== "No more war ! "trim/tail str       ;== "No more war !"; trim str          ; same as both /head and /tailtrim/all str        ;== "Nomorewar!" ; removes all spacestrim/with str "!"   ;== "Nomorewar"   ; removes a specific string

The trim word is very ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.