且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换功能中的特殊字符

更新时间:2023-09-17 23:41:34

在字符串中,反斜杠(\)具有特殊含义.它基本上说,不应以通常的意义来考虑以下字符.这就是为什么字符串"t"只是字母t,而"\ t"表示tab的原因.

In a string, the backslash (\) has a special meaning. It basically says that the following character should not be considered in its usual sense. This is why the string "t" is just the letter t, but "\t" means a tab.

此转义字符还用于在字符串中包含引号.例如,字符串"L'alouette"将引发错误,因为它包含的引号与字符串周围的引号类型相同.可以通过转义内部的':'L \'alouette'(或使用双引号:"l'alouette")来避免此问题

This escape character is also used to include quotation marks in a string. The string 'L'alouette', for example, will trigger an error, since it contains a quotation mark of the same type as the one surrounding the string. The problem can be avoided by escaping the inner ' : 'L\'alouette' (or by using double quotes: "l'alouette")

在您的示例中,OpenRefine理解您要转义第二个引号("\"),并认为您的字符串未完成.在这种情况下,正确的语法应该是转义\本身:"abab".replace('b', "\\")

In your example, OpenRefine understands that you want to escape the second quotation mark ("\") and considers that your string is not finished. The correct syntax, in this case, would be to escape the \ itself : "abab".replace('b', "\\")

特殊字符列表

| Special characters | Display               |
|--------------------|-----------------------|
| \'                 | Single quotation mark |
| \"                 | Double quotation mark |
| \\                 | Backslash             |
| \t                 | Tab                   |
| \b                 | Backspace             |
| \r                 | Carriage return       |
| \f                 | Formfeed              |
| \n                 | Newline               |

推荐文章