Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #8000 > unrolled thread
| Started by | Tim <timothygill07040@gmail.com> |
|---|---|
| First post | 2011-11-04 12:41 -0700 |
| Last post | 2011-11-04 23:50 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.javascript
basic Q on enclosing curly quotation/quot characters into strings Tim <timothygill07040@gmail.com> - 2011-11-04 12:41 -0700
Re: basic Q on enclosing curly quotation/quot characters into strings "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-04 22:05 +0200
Re: basic Q on enclosing curly quotation/quot characters into strings Timothy Gill <setsee@gmail.com> - 2011-11-04 13:42 -0700
Re: basic Q on enclosing curly quotation/quot characters into strings Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-04 21:40 +0000
Re: basic Q on enclosing curly quotation/quot characters into strings "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-04 23:50 +0200
| From | Tim <timothygill07040@gmail.com> |
|---|---|
| Date | 2011-11-04 12:41 -0700 |
| Subject | basic Q on enclosing curly quotation/quot characters into strings |
| Message-ID | <3ce3cfc5-e4fb-45b9-8e6f-328ee1f388e7@m19g2000vbm.googlegroups.com> |
I know some programming though not much JavaScript and I have to modify an existing JavaScript program that has an array assignment statement like labels[0] = "This does work for the typical case."; I need to change the "does" to "doesn't" where the single quote needs to be the proper curly single quote, because the font used to display this is a nice serif font. But the following change, using the "decimal numeric character reference" for right single quote ’ does not work: labels[0] = "This doesn’t work for the typical case."; I've looked online for 30 minutes and have tried concatenation and eval, but that does not work either. I just need to make this one change and get back to some other work. Anyone have the answer?
[toc] | [next] | [standalone]
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Date | 2011-11-04 22:05 +0200 |
| Message-ID | <j91gj2$f40$1@dont-email.me> |
| In reply to | #8000 |
11/4/2011 9:41 PM, Tim wrote: > I need to change the "does" to "doesn't" where the single quote needs > to be the proper curly single quote, because the font used to display > this is a nice serif font. A better reason is that the curly quotes are proper punctuation. But the use of punctuation should be consistent; use the same punctuation style in JavaScript-generated texts as in static content. > But the following change, using the > "decimal numeric character reference" for right single quote > ’ does not work: > > labels[0] = "This doesn’t work for the typical case."; It works in XHTML, but in classic HTML, no character references are recognized in <script> element content. And of course it does not work in an external JavaScript file. You can use the JavaScript construct for including a character in a string literal: \u followed by exactly four hexadecimal digits. In this example, "This doesn\u2019t work for the typical case." Alternatively, you can enter the curly single quote as such, as a character, provided that the document's character encoding makes that possible (e.g., windows-1252 or utf-8). -- Yucca, http://www.cs.tut.fi/~jkorpela/
[toc] | [prev] | [next] | [standalone]
| From | Timothy Gill <setsee@gmail.com> |
|---|---|
| Date | 2011-11-04 13:42 -0700 |
| Message-ID | <223d9ce4-6c87-4290-bd21-7e538245b443@r7g2000vbg.googlegroups.com> |
| In reply to | #8003 |
On Nov 4, 4:05 pm, "Jukka K. Korpela" <jkorp...@cs.tut.fi> wrote: > You can use the JavaScript construct for including a character in a > string literal: \u followed by exactly four hexadecimal digits. In this > example, > > "This doesn\u2019t work for the typical case." Jukka, thank you. This works fine for me. (And I agree with you, it's really about punctuation.) In the mean time, I found I have several other places where I have to make a word italic inside a string assigned to an array variable. Is there a similar easy way to do that? I found mention of some built-in methods like italic() and bold() that I assume I can use in an assignment statement, but have not tried this yet: word="this"; labels[0] = "The 5th word in " + word.italics() + " sentence should appear in italics."; Anyway, thanks again.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-04 21:40 +0000 |
| Message-ID | <4eb45bc7$0$28523$a8266bb1@newsreader.readnews.com> |
| In reply to | #8012 |
On Fri, 04 Nov 2011 13:42:04 -0700, Timothy Gill wrote: > word="this"; > labels[0] = "The 5th word in " + word.italics() + " sentence should > appear in italics."; > Anyway, thanks again. What you do is create embedded html markup in the string, eg labels[0] is stored as "The 5th word in <i>this</i> sentence should appear in italics." Whether it displays the stored text or the html interpretation of it depends on the context in which the string is being used. If you use labels[0] in an alert box, or assign it to the value of a button, for example, you will see the markup. However, if you assign it as the innerHTML of a <td>, <li>, <hN>, <p> etc element, it will display the word "this" italicised. eg see http://www.sined.co.uk/tmp/italics.htm and click on "a button" Rgds Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Date | 2011-11-04 23:50 +0200 |
| Message-ID | <j91mm9$q4n$1@dont-email.me> |
| In reply to | #8012 |
11/4/2011 10:42 PM, Timothy Gill wrote:
> In the mean time, I found I have several other places where I have to
> make a word italic inside a string assigned to an array variable. Is
> there a similar easy way to do that?
No, it's quite different from using the \u notation to enter characters.
Italics and bolding are stylistic presentation features, so they don't
make a character difference. They do not belong to plain text, and a
JavaScript string as such is plain text.
A plain text string may get interpreted as non-plain text when processed
by suitable software. So if you use, say
var foo = "Hello <i>world</i>"
in JavaScript, then use it to put content into an HTML element, e.g.
document.getElementById('bar').innerHTML = foo
(assuming markup like <div id=bar></div> for example), then web browsers
will treat the string as marked-up text and render <i>world</i> by
displaying the word world in italics.
(Beware that tags like </i> cause problems if your JavaScript code
appears inside an HTML document. Better put it in an external JavaScript
file.)
But on the other hand, if you do alert(foo), then the string is
displayed literally.
To be very exact, and very theoretical, I need to add that there _are_
Unicode characters that denote italic letters, such as U+1D44E
(mathematical italic small a). You don't want to use them, for a
multitude of reasons:
* They are meant for use in math texts, not general usage.
* They have very limited support in fonts (you need something like the
Code2001 font to get them rendered).
* They are non-BMP characters (outside the "16-bit subspace" of
Unicode), which means that JavaScript implementations need not support
them (though modern implementations generally do).
* Being non-BMP, they cannot be written directly using the \u notation,
which takes just 4 hex digits. Instead, it needs to be written using a
surrogate pair, e.g. as
'\uD835\uDC4E'
and this in turn means that such a character counts as two e.g. when
computing the length of a string.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web