Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to preserve leading spaces 1

Status
Not open for further replies.

xwb

Programmer
Jul 11, 2002
6,828
GB
How do I preserve leading spaces with CreateTextNode. I've got something like
Code:
sub AddHowTo (txt)
   HowToTxt.appendChild document.CreateTextNode (txt)
   HowToTxt.appendChild document.CreateElement ("br")
end sub

AddHowTo "m = (y2 - y1)/(x2 - x1)"
AddHowTo "  = " & cstr(y2 - y1) & " / " & cstr(x2 - x1)
AddHowTo "  = " & cstr(m)
I'd like to preserve the leading space so that all the = line up.
 
Three factors determine the outcome.
[1] With a style inherited a font-family of monospace.
[2] With space being non-breakable space to avoid being collapsed.
[3] Internal speaks unicode, so the script has to comply.

I suppose HowToTxt be some div or something. Let me suppose it is of id "sid" to remian generic in the answer.
[tt]
sub setFontStyle
dim HowToTxt
set HowToTxt=document.getElementById("sid")
HowToTxt.style.fontFamily="monospace"
set HowToTxt=nothing
end sub
sub AddHowTo (txt)
dim HowToTxt
set HowToTxt=document.getElementById("sid")
HowToTxt.appendChild document.CreateTextNode (txt)
HowToTxt.appendChild document.CreateElement ("br")
set HowToTxt=nothing
end sub
sub doit 'the workhorse
setFontStyle
'here all the necessary set up of 2d-line variables x1,x2,y1,y2,m etc
AddHowTo replace("m = (y2 - y1)/(x2 - x1)"," ",chrw(&ha0))
AddHowTo replace(" = " & cstr(y2 - y1) & " / " & cstr(x2 - x1)," ",chrw(&ha0))
AddHowTo replace(" = " & cstr(m)," ",chrw(&ha0))
end sub
[/tt]
 
I didn't know 160 was a non-breaking space. Thanks for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top