简体   繁体   English

如何在字符串中键入撇号(')?

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

What is the proper syntax to display 25' as output description? 显示25'作为输出描述的正确语法是什么?

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. 在JSON文件中,所有字符串都用双引号分隔,您只需编写撇号即可。

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 "'" ). 在JavaScript对象文字中,您还可以在其中用撇号定界字符串,然后将需要使用反斜杠'\\'' (双引号定界符:只是"'" )对它们进行转义。

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; 在HTML中,您可以将其替换为实体 &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 . ,如果您不想使用建议的UTF-8字符 ,则可以在JSON和JavaScript中将其替换为转义序列\′

Like so: 像这样:

foo: '25′'

Notice that the prime character and the apostrophe character are two different Unicode characters. 请注意, 主要字符撇号字符是两个不同的Unicode字符。 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: 这是在sans-serif中的外观:

25′, and 25′′ 25'和25''

var sizeData = [ var sizeData = [
{description:\\'Recommended sizes listed below\\', value:\\'\\', text:\\'Select Size\\'}, {说明:\\'建议的尺寸如下所列\\',值:\\'\\',文字:\\'选择尺寸\\'},
{description:\\'Boat < 25 ′, value:\\'size0\\', text:\\'Size 0\\'} ]; {description:\\'Boat <25',value:\\'size0 \\',text:\\'Size 0 \\'}];

You can enclose a (') using a "". 您可以使用“”括起(')。 Basically like this " ' ". 基本上像这样的“”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制密钥为字符串类型(而不是数字或符号)? - How can I enforce a key to be of type string (and not number or symbol)? 如何在JavaScript中将字符串转换为符号 - How to convert a String to a Symbol in JavaScript 如何在javascript中将字符串转换为符号 - How to convert string to symbol in javascript Angular Prime NG - 如何在路由器链接中为 Prime NG 步骤添加查询字符串 - Angular Prime NG - How to add a query string in the router link for the Prime NG steps 如何从字符串中删除符号以及此符号之后的所有内容 - How to remove symbol and everything after this symbol from a string 如何从字符串中删除第三个符号并在没有第三个符号的情况下发出警报 - How to cut third symbol from string and alert it without third symbol 如何将 JavaScript 符号转换为没有“符号(”前缀的字符串? - How to convert a JavaScript Symbol to a string without the “Symbol(” prefix? 如何仅过滤数组中符号类型的值? - How to filter only values with type Symbol in an array? 为什么`keyof any`具有`string |类型? 编号 打字稿中的符号`? - Why does `keyof any` have type of `string | number | symbol` in typescript? Typescript - 索引表达式参数必须是&#39;string&#39;,&#39;number&#39;,&#39;symbol&#39;或&#39;any&#39;类型 - Typescript - An index expression argument must be of type 'string', 'number', 'symbol' or 'any'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM