This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display each character on a new line

 
sadagi korbu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I am a beginer in html & javascript. I am trying to write a program which displays each character on a new line when a string is provided by the user.

Can someone help me with the same.

Regards
 
Christophe Porteneuve
Author
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sadagi,


I am a beginer in html & javascript. I am trying to write a program which displays each character on a new line when a string is provided by the user.


Can you be more specific? What do you mean, "provided by the user?" Is it a form text input field? Is it a prompt dialog? Is it something else?

Also, where do you want to display the result? In a message dialog? In the web page, as HTML?

Finally, assuming you're trying to do that processing in JavaScript, the core of it can be done using regular expressions. Say you obtained the user's text in a variable called text. If you want to display it as independent lines in a dialog box (not HTML), you could go:



If you want HTML (therefore requiring <br/> tags, unless your CSS respects line breaks), you would just change the replace expression like this:



So let's say you have an element with id="foo" that you want to update with the result, you'd go:



I hope this helps,

[ February 12, 2008: Message edited by: Christophe Porteneuve ]
[ February 12, 2008: Message edited by: Christophe Porteneuve ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic