Search code examples
serializationerlangerl

Erlang - serialize a string (with no newlines/carriage returns)?


I've seen some answers to this in other programming languages, but not a specific erlang one. I'm able to read the file and I use:

re:replace(Subject, RE, Replacement, Options)

specifically:

re:replace(Content, "\r" , " ",[global,{return,list}]),

to remove those escape sequences (I believe that's what they are called)

And it perfectly replaces all the \r with a space. So my question is:

1) is there a way to put multiple replacements in RE, so I could also remove "\n"?
2) is there a different/better/more efficient way to do it?


Solution

  • It's the basics of regular expressions.

    In your first question, you can use the solution:

    re:replace(Content, "[\r\n]", " ", [global, {return, list}])
    

    Erlang string syntax is not convenient enough, if you need to do a lot of very complex string processing, you should consider using another language.