Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 7, 2013

Split operators from string in javascript



1. First Method to remove operators:

 '123+456-321'.split(/([-+\/*])/) // gives == ["123", "+", "456", "-", "321"] 

2. Second Method to remove operators:


<script type="text/javascript">
var strIn = '123+456-321';
var tarrN = strIn.split(/\D/);
var tarrO = strIn.split(/\+|\-|\*|\//);
alert(tarrN.join('\n')+'\n\n'+tarrO.join('\n'));
</script>

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment