0

I want to remove ALL whitespace from a string, that is, if I have: rna= "AUG UUU UCU" Then I'd like to have: new_rna="AUGUUUUCU"

How do I do that in Elixir?`

I looked up way of trimming strings but that hardly helps for whitespace in the interior of a string.

1 Answers1

0

You can use regex:

Regex.replace("~r/\s/u", [STRING HERE], "")

Replace [STRING HERE] with your string.

Regex explained:
~r/: Tells Elixir to use regex
\s: Match whitespace
/u: Match unicode characters (will only match unicode spaces)

In your case, try this code:

new_rna = Regex.replace("~r/\s/u", rna, "")
Fastnlight
  • 922
  • 2
  • 5
  • 16