[erlang-questions] STRCMP or something like that

Simon St.Laurent simonstl@REDACTED
Mon Dec 24 16:22:52 CET 2012

On 12/24/12 9:28 AM, Evren Bayraktar wrote:
> Hi everyone,
> I'm having trouble with Erlang  I hope someone can help me. I'm really
> newbie in Erlang :)
> I need to something like strcmp in php.
> For example;
> I have a two different string, Alicia and Alex. I need to steady order
> for them. By parsing each letter I guess I can do that.
> $A. returns 65 so I can't compare with first letters then $l. returns
> 108 but they are same too.
> Now, $e. returns 101 and $i. returns 105. By using this numbers I can
> give correct order, first Alex then Alica.

lists:sort will order them, as was noted, but if you just need 
comparison, you don't need to go character by character. < and > are 
fine with strings -

1> "Alicia" < "Alex".
2> "Alicia" > "Alex".

I'm contemplating writing a simple wrapper library for the string and 
list functions that looks more familiar to programmers coming from other 

Simon St.Laurent
Introducing Erlang

> I mean, imagine a function which compare two different variable, by
> using their ascii codes it will return
> correct order.
> Function("alicia", "alex") ---> will return alex+alicia
> I hope someone will help me
> Best Regards
> Evren

More information about the erlang-questions mailing list