parsing text

Wes James comptekki@REDACTED
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:

lists:nth(424,B).
<<"<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
int?

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)
case
    is_integer(A) -> A;
    is_integer(B) -> B;
    is_integer(C) -> C;
end.


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)
catch
    throw:Term -> Term;
    exit:Reason -> {'EXIT',Reason};
    error:Reason -> {'EXIT',{Reason,erlang:get_stacktrace()}}
end.


and so forth....

-wes


More information about the erlang-questions mailing list