Solved

Finding character position

Posted on 2011-03-15
14
286 Views
Last Modified: 2012-05-11
Hello,

i trying to make the following ,  the java code is asking for the name and a number,
what the number should show the character in that position for example i give the name : persia and the number 3
it should give

PERSIA
R

i did the uppercase part but im stuck at the second part Please help


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		
		number = parseInt (prompt("give a number"));
		
        </script>
		
		
		
	</body>
	

</html>
</body>
</html>

Open in new window

0
Comment
Question by:kensy11
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136234
you need to use the charAt() method

http://www.w3schools.com/jsref/jsref_charat.asp

alert(name.charAt(2));
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35136238
alert(name.charAt(number));
0
 

Author Comment

by:kensy11
ID: 35136254
i already did it but not working

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		number = parseInt (prompt("give a number"));
		document.write(" character is: " + number + "<br />");
        </script>
	</body>
</html>
</body>
</html>

Open in new window

0
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35136257
alert(name.charAt(number).toUpperCase());
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136277
This looks like works:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136284
replace line 16 with

document.write(" character is: " + name.charAt(number) + "<br />");
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136289
sorry it should be


document.write(" character is: " + name.charAt(number-1) + "<br />");
0
 

Author Comment

by:kensy11
ID: 35136292
aah thanks, i got it now
one other question how can i count the whole text ten
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136301
if you want to count the length of the text, then use name.length

http://www.w3schools.com/jsref/jsref_length_string.asp
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136321
This prints the length of the string

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136355
thanks again sorry one other question
 
for example i give the name persia and the number is 2

how can i write the name form the 2 position , in this case i shuld look like  RSIA

thanks again
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136368
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 35136379
counting form zero:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136383
Thank you all
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 26
Html Table Looping (part 2) 5 27
100% tall div not scrollable on iPhone 3 20
Angular won't showing my array result in HTML 3 26
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question