title: extract data from string in erlang
body: <p>I declared Line variable with this syntax :</p>
  
  <p>Line ="1;nabil;chouaib;france;27", </p>
  
  <p>I want to declared 5 variables : <strong>Id , Firsname , lastname , address , age</strong></p>
  
  <p>The Id  should contains  1
  The Firsname should contains nabil
  The lastname should contains chouaib
  The address should contains france
  The age should contains 27 </p>
  
  <p>so I have to parse the contents of the variable <strong>Line</strong> </p>
  
  <p>The  separator in thi case is <strong>;</strong></p>
  
  <p>I have this function : </p>
  
  <pre><code>test()-&gt;
  
      ForEachLine = fun(Line,Buffer)-&gt; 
                            io:format("Line: ~s~n",Line),
  
  
                            [IdStr, FirstnameStr, LastnameStr, AddressTr, AgeStr] = string:tokens(Line, ";"),
     Buffer end,
  
   InitialBuffer = [],
  
   csv:parse("/var/lib/mysql/test/person1.csv",ForEachLine,InitialBuffer).
  </code></pre>
  
  <p>but when I excecute the test function T have this error :    </p>
  
  <pre><code>1&gt; model:test().
  Line: 1;nabil;chouaib;france;27
  ** exception error: no match of right hand side value [["1;nabil;chouaib;france;27"]]
       in function  model:'-test/0-fun-0-'/2
       in call from csv:start_parsing/3
  </code></pre>
  
  <p>the  problem is related to this line : </p>
  
  <pre><code>[IdStr, Firstname, Lastname, Address, AgeStr] = string:tokens(Line, ";") 
  </code></pre>
  
  <p>I think that the type of <strong>Line</strong> is not a string ( but in the consol before the error this line is displayed  <code>Line: 1;nabil;chouaib;france;27</code> )</p>
  
  <p>so I should just know the type of <strong>Line</strong></p>
  
  <p>the csv.erl module is :</p>
  
  <pre><code>%%% --- csv parser in Erlang. ------
  %%% To help process large csv files without loading them into
  %%% memory. Similar to the xml parsing technique of SAX
  
  -module(csv).
  -compile(export_all).
  
  parse(FilePath,ForEachLine,Opaque)-&gt;
      case file:open(FilePath,[read]) of
          {_,S} -&gt;
              start_parsing(S,ForEachLine,Opaque);
          Error -&gt; Error
      end.
  
  start_parsing(S,ForEachLine,Opaque)-&gt;
      Line = io:get_line(S,''),
      case Line of
          eof -&gt; {ok,Opaque};
          "\n" -&gt; start_parsing(S,ForEachLine,Opaque);
          "\r\n" -&gt; start_parsing(S,ForEachLine,Opaque);
          _ -&gt; 
              NewOpaque = ForEachLine(scanner(clean(clean(Line,10),13)),Opaque),
              start_parsing(S,ForEachLine,NewOpaque)
      end.
  
  scan(InitString,Char,[Head|Buffer]) when Head == Char -&gt; 
      {lists:reverse(InitString),Buffer};
  scan(InitString,Char,[Head|Buffer]) when Head =/= Char -&gt;
      scan([Head|InitString],Char,Buffer);
  scan(X,_,Buffer) when Buffer == [] -&gt; {done,lists:reverse(X)}.
  scanner(Text)-&gt; lists:reverse(traverse_text(Text,[])).
  
  traverse_text(Text,Buff)-&gt;
      case scan("",$,,Text) of
          {done,SomeText}-&gt; [SomeText|Buff];
          {Value,Rem}-&gt; traverse_text(Rem,[Value|Buff])
      end.
  
  clean(Text,Char)-&gt; 
      string:strip(string:strip(Text,right,Char),left,Char).
  </code></pre>