[erlang-questions] Which is best? string:concat or ++?

Wes James comptekki@REDACTED
Mon May 7 16:12:45 CEST 2012


On Mon, May 7, 2012 at 7:31 AM, Paul Barry <paul.james.barry@REDACTED> wrote:
> Hi folks.
>
> This might be a case of a dumb question, but here goes anyway.  :-)
>
> I have two strings, A and B.  Is it better to use:
>
>   string:concat(A, B)
>
> or
>
>    A ++ B
>
> when combining them to create a new string?  I'm writing some code
> that generates a chunk of HTML.  I know that using ++ on big lists is
> regarded as a "no-no", but is it acceptable here?
>


You may want to consider, if possible, to move all your string
operations to binary format.

For example:

A = <<"<html><head><title>">>.

B = <<"My Title">>.

C = <<"</title></head><body>hi</body></html>">>.

All = <<A/binary, B/binary, C/binary>>.

The All part could just be a return from a fun, etc.

-wes



More information about the erlang-questions mailing list