Remove a substring/ string pattern of a string in Erlang
问题 I have an xml string like S = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3/></B>". I want to remove the end tag </B> S2 = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3/>" How can I achieve this? 回答1: If you only want to remove the specific string literal </B> then getting a sublist will do the trick: S = "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3\"/></B>", lists:sublist(S, 1, length(S) - 4). %%= "<B xmns=\"som2\"> <a other='v1' more='v2'/><b some=\"v3\"/>"