/    Sign up×
Community /Pin to ProfileBookmark

Inserting line breaks between characters

I want to create some vertical text that I want to display. I have a string and what I want to do is create an new string with a line break between each character from the original string then use that to display on the page as vertical text. What I am stuck on is how to get the line break between each character. Any help would be appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — Perhaps wrap a <div> around each string?

or

I think you have to create a <br> element by doing something like...

document.createElement('br') and inserting it into the document between the 2 strings.
Copy linkTweet thisAlerts:
@jonschatzauthorJun 30.2009 — Perhaps wrap a <div> around each string?

or

I think you have to create a <br> element by doing something like...

document.createElement('br') and inserting it into the document between the 2 strings.[/QUOTE]

I want a line break between each character in the string. My dificulty is getting the line break '/n' between each character.
Copy linkTweet thisAlerts:
@mataichiJun 30.2009 — Interesting.

Well, you could do something like this to get every character within the string.

[CODE]for (var x=0; x<str.length; x++) {
alert(str.charAt(x));

}[/CODE]
Copy linkTweet thisAlerts:
@CharlesJul 01.2009 — alert (str.replace (/(.)/g, '$1n')
Copy linkTweet thisAlerts:
@hacketJul 02.2009 — This should give you what you want.

Code:

for (var x=0; x<str.length; x++) {

document.write(str.charAt(x));

document.write("<br>");

}
×

Success!

Help @jonschatz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...