| Author |
Message |
< Erlang ~ Perl Guy does keycode filters via Bit String Comphresion |
| sexmith |
Posted: Tue Mar 03, 2009 3:16 am |
|
|
|
Joined: 03 Jan 2008
Posts: 5
Location: Ohio USA
|
I have a few Ajax web clients that send a text field upon keyup events within javascript.
Upon reaching the server I have \r \t \cM ^M etc within the text string I receive when I just want the integer/number.
In Perl I would use regex
Code:
$textstring = "\r12\t34\cM56\n7890\n";
$textstring =~ s/[\t\cM\n\r]+//g;
print $textstring;
>1234567890
And the above works within LAMP/perl
However I am trying to implement this in yaws/erlang.
Blogs etc suggested bit string comprehension for this.
I found that filters added to bit string comprehension really does work once you force yourself to think differently.
Code:
Tstring = << "\r12\t34\cM56\nAaBbCdDeeEE7890\n" >>.
Result = << << (X) >> ||<<X>> <= Tstring, X >47, X<58 >>.
Result.
<<"1234567890">>
Useful Erlang functions when doing this sort of thing are:
1) list_to_binary
2) binary_to_list
3) list_to_integer
First you do it right. Then you do it better.
Is there a better solution for this.
R. Sexmith |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|