Sunday, July 1, 2018

JS:Split a user string

Splitting a user string

<!DOCTYPE html>
<html>
<head>

<style>
body {background-color: pink;}
h2   {color: blue;}
p    {color: red;}
</style>

</head>
<body>
<h2 align=center>Spliting Input Strings</h2>
Input a string: <input type="text"  id="string"><br><br>

<p><span id="split"></span></p><br><br>
<input type="button" onclick="myFunction()" value="Split String">
<script>
function myFunction(){
var inputString=document.getElementById("string").value;
var string = "Central University";
    var result = inputString.split(" ");
    var l =result.length;
    var i;
    var res='[';
    for( i=0;i<l;i++){
    res = res + '" '+result[i]+'" ';
   
    }
        res=res+']';
    document.getElementById("split").innerHTML=res;
    }
</script>
</body>
</html>

output

No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows