- # Split self using '\n' is separator.
- # "hello\nworld".split # -> ["hello","world"]
- meth split: Array[String] do return split_with('\n')
+ # @deprecated alias for `split`
+ fun split_with(p: Pattern): Array[String] do return self.split(p)
+
+ # Replace all occurences of a pattern with a string
+ #
+ # "hlelo".replace("le", "el") # -> "hello"
+ # "hello".replace('l', "") # -> "heo"
+ fun replace(p: Pattern, string: String): String
+ do
+ return self.split_with(p).join(string)
+ end
+
+ # Escape the four characters < > & and " with their html counterpart
+ #
+ # "a&b->\"x\"".html_escape # -> "a&b->"x""
+ fun html_escape: String
+ do
+ var ret = self
+ if ret.has('&') then ret = ret.replace('&', "&")
+ if ret.has('<') then ret = ret.replace('<', "<")
+ if ret.has('>') then ret = ret.replace('>', ">")
+ if ret.has('"') then ret = ret.replace('"', """)
+ return ret
+ end