Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!-- Segrate the numeric and non-numeric part -->
- <html>
- <head>
- <title>String Operations</title>
- <script type="text/javascript">
- function segregate()
- {
- var st=document.getElementById('userString').value;
- var stl=st.length;
- var nstr=new Array(2);
- nstr[0]="";
- nstr[1]="";
- for(var i=0;i<stl;i++)
- {
- if(isNaN(st.charAt(i)))
- nstr[0]=nstr[0]+st.charAt(i);
- else
- nstr[1]=nstr[1]+st.charAt(i);
- }
- console.log('Non-numeric part : ' + nstr[0] + ' & numberic : ' + nstr[1]);
- }
- </script>
- <!-- The <style> section below is optional -->
- <style type="text/css">
- body{
- margin:0px;
- padding:0px;
- font-size:0.90em;
- font-family:Helvetica,sans-serif;
- }
- p{
- color:#FFF;
- background-color:#FF5533;
- width:120px;
- padding:5px 10px;
- margin:3px;
- text-align:center;
- }
- p:hover{
- background-color:#FF9955;
- cursor:pointer;
- }
- </style>
- </head>
- <body>
- Enter any string of characters
- <input type="text" id="userString" size="15"> <br />
- <p onclick="segregate()">Segregate</p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement