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

Paul Barry <>
Mon May 7 16:18:23 CEST 2012


I take it that doing it that way is "faster" than string manipulation
(or is there some other reason for this suggestion)?

On 7 May 2012 15:12, Wes James <> wrote:
> On Mon, May 7, 2012 at 7:31 AM, Paul Barry <> 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



-- 
Paul Barry, w: http://paulbarry.itcarlow.ie - e: 
Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.



More information about the erlang-questions mailing list