parsing text

Wes James <>
Thu Apr 29 20:39:38 CEST 2010

I have a function grabbing a page and I'm pulling text out of the
result.  I can get the line:

<<"<B>Page Counter</B></TD><TD>4880</TD></TR>">>

but 4880 will eventually get to 10000, etc.

I can do

string:substr(binary_to_list(lists:nth(424,B)), 34, 4).

to get the 4880 out, but to do a check for > 9999 would I grab
position 34 + the rest of the text then test positions after that for

or maybe something like this?

A=string:substr(binary_to_list(lists:nth(424,B)), 34, 6)
B=string:substr(binary_to_list(lists:nth(424,B)), 34, 5)
C=string:substr(binary_to_list(lists:nth(424,B)), 34, 4)
    is_integer(A) -> A;
    is_integer(B) -> B;
    is_integer(C) -> C;

Hmm - A, B, and C will be strings though so is_integer won't work.  If
I do list_to_integer(A), I guess I can write something like this:

try list_to_integer(A)
    throw:Term -> Term;
    exit:Reason -> {'EXIT',Reason};
    error:Reason -> {'EXIT',{Reason,erlang:get_stacktrace()}}

and so forth....


More information about the erlang-questions mailing list