Thứ Sáu, 27 tháng 5, 2011

Using Javascript, how do I insert newlines/force a carriage return when saving a file?

Using Javascript, how do I insert newlines/force a carriage return when saving a file?

The application I’m having problems with is Notepad. I’m trying to save a text file showing a pyramid of numbers as seen below using Javascript (bad I know, but I’m just trying it out).

1
22
333
44
5

I am able to save it, but once I open up the file in Notepad, all of my carriage returns, newlines, and other formatting characters disappear. I’m able to view it all through WordPad and I have a preview option that when I hit “View Source” shows that it’s been formatted correctly so I know it’s there, but Notepad refuses to acknowledge that format in my saved files.

So, how do I force Notepad to format my file properly?
My Javascript line is something like this:

testdoc.write(“1n22n333n44n5″);

Answer by ericjames
the string “n” indicates a new line.

try outputting your text like this:
var a =1, b=2, c=3, d=4, e=5;
var outputString=a+”n”+b+”"+b+”n”+c+”"+c+”"+c+”n”+d+”"+d+”/n”+e;

Hope this helps!

Answer by nix1602
Don’t use Notepad, it is unreliable, there is a free alternative Notepad++
http://notepad-plus.sourceforge.net/uk/site.htm

Answer by Kevin
You need a carriage return and line feed:

testdoc.write(“1rn22rn333rn44rn5″);

What do you think? Answer below!

Souvenir Shopping With Virtualtatans
hit pyramid

Image by BrittneyBush
As their visit drew to a close, the Virtualtatans and I hit the souvenir shop.

Left to right, top to bottom:

1) Beaded bracelets through a magnifying glass that happened to be lying nearby.
2) ZenRhino shops for a backup hat
3) MJ was as bemused by the cow cap as I was – there is an embroidered cow face on the front, too.
4) Madi tried on a little sparkly number for us
5) I decided the headband with attached fake red curls just wasn’t really me.
6) The better to see the shlock with, my dear
7) We were all disappointed to find that the pink flowered jellies didn’t come in our size 8) Who DOESN’T need King Tut socks?
9) I had to rescue ZenRhino from the jaws of danger
10) Madi was found swimming gleefully amongst the turquoise bracelets
11) MJ decided a neon green scorpion pyramid would really make her bathroom complete.
12) They’re certainly not short on shirts here!

Created with fd’s Flickr Toys.

Bored

I have done all of these and i need some new ones

Annoy total strangers
Ask questions that nobody can answer
Ask stupid questions
At the bottom of escalators yell "MY SHOELACE!"
Bark at people at the grocery store
Be a spy
Become a tic-tac addict
Blow bubbles with bubble gum
Build a pyramid
Build a tree house in the middle of a field
Burp the happy birthday song
Carpet your ceiling
Change your name…Daily
Chew your arm until someone notices
Crush pop cans with croquet mallets
Declare April 6th "slap butt day" at your school and actively celebrate it
Discover the answer to the ultimate question…then the question itself…
Duct tape a spoon to the wall and wait for it to fall
Find a bug and chase it
Flash your mailman
Go to McDonald's and pretend that you can't speak English
Go to your local museum, and try to get kicked out
Invent something
Kiss your elbow, if you can
Lay a long straight line of masking tape on the floor. Now spin around really fast then try walking on the masking tape
Learn insulting words in other languages
Make a trash can a basketball hoop and throw crumpled up paper for baskets
Make shoelaces out of noodles
Out of nowhere, or when it is quite, say loud "when I say heeee-aay , you say hoooo, Heeee-aay" and see how many people say "ho"
Pay for expensive things with pennies
Plant M&M's
Play bottle cap hockey…with pens as the sticks and a bottle cap an a puck
Run to a window, then say "Sorry I thought I saw the Bat-signal."
Shout "shut up, SHUT UP," and hit your head on a table
Test thin ice…with a pogo stick
Turn your TV upside down and watch it
Walk around as a body guard for a day for one of your friends
Walk around the room begging for spare change
Walk extra fast all day
Wear duck tape – (That started my duct tape clothes)
When you buy something ask to get your picture taken with the clerk
Write complaint letters to companies that annoy you

Answer by Winter
Use your imagination.

Answer by Drama Queen™
come on here

Answer by thom
ponder the ultimate question of life, the universe and everything

Answer by Peanut Butter Jelly Man
Try getting laid.

Answer by Ryan W
masturbate

Add your own answer in the comments!
Student cooking site a recipe for success
Senior Katie VanderMolen’s cooking blog features photos of her creations as well as single-serving recipes. The stereotypical college diet consists of late-night pizza, various Ramen creations, and anything that involves the phrases “just add water” and “microwaveable.”
Read more on The DePaulia

Yes.. Aran got nerfed with that wierd damage cap. Its not possible to hit high dmg on more monsters in 1 overswing. Check my old pyramid pq video here: www.youtube.com Warning: Its old. (really old) Song: Techno Dream Trance- In The Distance Thx for watching!
Video Rating: 4 / 5


Không có nhận xét nào:

Đăng nhận xét