0% found this document useful (0 votes)
27 views6 pages

CSS - Exp 5 - PDF - UPDATED TUESDAY

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

CSS - Exp 5 - PDF - UPDATED TUESDAY

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name: Ansari Abdullah Roll no: 220402

Sub: Client-Side Scripting (CSS) Branch: CO

Experiment No. 5: Develop Javascript to implement Strings


▪ Write a program to create string using different methods and finding length of string

CODE:
<html>
<head>
<title> Exp 5_1 </title>
<script>
var str="Hello World";
var str2=new String("Hello!!!");
document.write(str+"<br>");
document.write("Length of string 1: "+str.length);
document.write("<br>"+str2);
document.write("<br> Length of string 2: "+str2.length);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program to find index of particular string using different parameters

CODE:
<html>
<head>
<title> Exp 5_2 </title>
<script>
var a="Hello World";
var b=a.indexOf("Hello");
var c=a.indexOf("l",7);
document.write("Position of Hello: "+b+"<br>"+"Position of l after
7th location: "+c+"<br>");
var d=a.lastIndexOf("l");
var e=a.lastIndexOf("o",5);
document.write("Last index of l: "+d+"<br>"+"Last index of o from
5th index: "+e);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program for extracting the string using different parameters

CODE:
<html>
<head>
<title> Exp 5_3 </title>
<script>
var str="JavaScript is an interpreted language with object-oriented
capabilities.";
document.write("String: "+str+"<br>");
document.write("<br> Substring from index 5 till end:
"+str.substring(5));
document.write("<br> Substring from index 5 to 25:
"+str.substring(5,25));
document.write("<br> Substring from index 5 to 35:
"+str.substring(35,5));
document.write("<br> Slice method demonstration: "+str.slice(-40,-
5));
document.write("<br> Slice method demonstration: "+str.slice(30,-5));
document.write("<br> Slice method demonstration: "+str.slice(0,-10));
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:
▪ Write a program for replacing and converting string to uppercase and lowercase using
different methods and parameters

CODE:
<html>
<head>
<title> Exp 5_4 </title>
<script>
var str="JavaScript is an interpreted language with object-oriented
capabilities.";
document.write("String: "+str+"<br>");
document.write("Using replace():
"+str.replace("capabilities","features"));
var u=str.toUpperCase();
document.write("<br> Converting into uppercase: "+u);
var l=str.toLowerCase();
document.write("<br> Converting into lowercase: "+l);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:
▪ Write a program to concatenate two strings

CODE:
<html>
<head>
<title> Exp 5_5 </title>
<script>
var str1="JavaScript";
var str2=" is case sensitive,";
var str3=" light in weight,";
var str4=" supports object-oriented programming";
var str5= str1.concat(str2,str3," and ",str4);
document.write(str5);
document.write("<hr> 220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

▪ Write a program to trim the whitespace, find character code as well as the character at
specified index

CODE:
<html>
<head>
<title> Exp 5_6 </title>
<script>
var a=" Hello ";
var x=a.trim();
var b="Abdullah";
var n=b.charCodeAt(2);
var c=String.fromCharCode(75,81);
document.write("Use of trim(): "+x+"<br>");
document.write("Unicode of character at index 2: "+n+"<br>");
document.write("Character of unicode 75 and 81: "+c+"<hr>");
document.write("220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:
▪ Write a program to convert string to number using different function

CODE:
<html>
<head>
<title> Exp 5_7 </title>
<script>
var a=parseInt("0x10");
var b=parseInt("10.6");
var c=parseInt("017");
var d=parseFloat("1.5");
var e=parseFloat(" 12 ");
var f=15;
var x=f.toString(8);
var y=f.toString(16);
document.write("a= "+a+"<br>");
document.write("b= "+b+"<br>");
document.write("c= "+c+"<br>");
document.write("d= "+d+"<br>");
document.write("e= "+e+"<br>");
document.write("x= "+x+"<br>");
document.write("y= "+y+"<hr>");
document.write("220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:
▪ Write a program to show usage of Split method

CODE:
<html>
<head>
<title> Exp 5_8 </title>
<script>
var str="JavaScript is a scripting language.";
var a=str.split("");
var b=str.split(" ",4);
var c=str.split("",4);
document.write(a+"<br>");
document.write(b+"<br>");
document.write(c+"<hr>");
document.write("220402-Ansari Abdullah");
</script>
</head>
</html>

OUTPUT:

You might also like