简体   繁体   中英

How to type the prime ( ' ) symbol in a string?

What is the proper syntax to display 25' as output description?

Example:

var sizeData = [            
    {description:'Recommended sizes listed below', value:'', text:'Select Size'},                   
    {description:'Boat < 25 &prime;, value:'size0', text:'Size 0'},
    {description:'25-35 Foot Boat', value:'size2', text:'Size 2'},
    {description:'40-45 Foot Boat', value:'size3', text:'Size 3'},
];

In a JSON file, where all strings are delimited with double quotes, you can just write apostrophes.

In a JavaScript object literal, where you can delimit strings with apostrophes as well, you then will need to escape them with a backslash: '\\'' (dobule quote delimiters: just "'" ).

The prime symbol - which is different from the apostrophe you typed - can be inserted without harm. Depending on the encoding of your file, you might need to write it a bit different. In HTML you can replace it with the entity &prime; , in both JSON and JavaScript you can replace it with the escape sequence \′ if you do not want to use the recommended UTF-8 character .

Like so:

foo: '25′'

Notice that the prime character and the apostrophe character are two different Unicode characters. You can put the prime character inside a single-quote encapsulated string normally.

Btw, above the prime character is printed in monospace font. This is how it looks in sans-serif:

25′, and 25′′

var sizeData = [
{description:\\'Recommended sizes listed below\\', value:\\'\\', text:\\'Select Size\\'},
{description:\\'Boat < 25 ′, value:\\'size0\\', text:\\'Size 0\\'} ];

You can enclose a (') using a "". Basically like this " ' ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM