Rectangle 27 125

You can find the full list here.

  • \t Insert a tab in the text at this point.
  • \b Insert a backspace in the text at this point.
  • \n Insert a newline in the text at this point.
  • \r Insert a carriage return in the text at this point.
  • \f Insert a formfeed in the text at this point.
  • \' Insert a single quote character in the text at this point.
  • \" Insert a double quote character in the text at this point.
  • \\ Insert a backslash character in the text at this point.

The list is missing Unicode and octal escapes: \u1234 \012 \01 \0

It's also missing the bell character \a and the null character \0.

\a
illegal escape character: String test = "\a";

"Unicode escapes are pre-processed before the compiler is run." -- Mark Peters. So they are different from the standard String escapes listed here. Thanks Jan for the comment to this answer

java - What are all the escape characters? - Stack Overflow

java string escaping
Rectangle 27 125

You can find the full list here.

  • \t Insert a tab in the text at this point.
  • \b Insert a backspace in the text at this point.
  • \n Insert a newline in the text at this point.
  • \r Insert a carriage return in the text at this point.
  • \f Insert a formfeed in the text at this point.
  • \' Insert a single quote character in the text at this point.
  • \" Insert a double quote character in the text at this point.
  • \\ Insert a backslash character in the text at this point.

The list is missing Unicode and octal escapes: \u1234 \012 \01 \0

It's also missing the bell character \a and the null character \0.

\a
illegal escape character: String test = "\a";

"Unicode escapes are pre-processed before the compiler is run." -- Mark Peters. So they are different from the standard String escapes listed here. Thanks Jan for the comment to this answer

java - What are all the escape characters? - Stack Overflow

java string escaping
Rectangle 27 124

You can find the full list here.

  • \t Insert a tab in the text at this point.
  • \b Insert a backspace in the text at this point.
  • \n Insert a newline in the text at this point.
  • \r Insert a carriage return in the text at this point.
  • \f Insert a formfeed in the text at this point.
  • \' Insert a single quote character in the text at this point.
  • \" Insert a double quote character in the text at this point.
  • \\ Insert a backslash character in the text at this point.

The list is missing Unicode and octal escapes: \u1234 \012 \01 \0

It's also missing the bell character \a and the null character \0.

\a
illegal escape character: String test = "\a";

"Unicode escapes are pre-processed before the compiler is run." -- Mark Peters. So they are different from the standard String escapes listed here. Thanks Jan for the comment to this answer

java - What are all the escape characters? - Stack Overflow

java string escaping
Rectangle 27 124

You can find the full list here.

  • \t Insert a tab in the text at this point.
  • \b Insert a backspace in the text at this point.
  • \n Insert a newline in the text at this point.
  • \r Insert a carriage return in the text at this point.
  • \f Insert a formfeed in the text at this point.
  • \' Insert a single quote character in the text at this point.
  • \" Insert a double quote character in the text at this point.
  • \\ Insert a backslash character in the text at this point.

The list is missing Unicode and octal escapes: \u1234 \012 \01 \0

It's also missing the bell character \a and the null character \0.

\a
illegal escape character: String test = "\a";

"Unicode escapes are pre-processed before the compiler is run." -- Mark Peters. So they are different from the standard String escapes listed here. Thanks Jan for the comment to this answer

java - What are all the escape characters? - Stack Overflow

java string escaping
Rectangle 27 1071

If you use an appropriate class or library, they will do the escaping for you. Many XML issues are caused by string concatenation.

There are only five:

"   "
'   '
<   &lt;
>   &gt;
&   &amp;

Escaping characters depends on where the special character is used.

<?xml version="1.0"?>
<valid>"'></valid>

The safe way is to escape all five characters in attributes, however, the > character needn't be escaped in attributes:

The ' character needn't be escaped in attributes if the quotes are ":

Likewise, the " needn't be escaped in attributes if the quotes are ':

<?xml version="1.0"?>
<valid attribute='"'/>
<?xml version="1.0"?>
<valid>
<!-- "'<>& -->
</valid>
<?xml version="1.0"?>
<valid>
<![CDATA["'<>&]]>
</valid>

All 5 special characters must not be escaped in XML processing instructions:

<?xml version="1.0"?>
<?process <"'&> ?>
<valid/>

@Pacerier, I beg you not to write your own XML/HTML escaping code. Use a library function or you're bound to miss a special case.

Also for line breaks you need to use and for tab, if you need these characters in an attribute.

If you're going to do a Find/Replace on these, just remember to do the replacement before the others.

From Wikipedia: "All permitted Unicode characters may be represented with a numeric character reference." So there are a lot more than 5.

escaping - What characters do I need to escape in XML documents? - Sta...

xml escaping character
Rectangle 27 1046

If you use an appropriate class or library, they will do the escaping for you. Many XML issues are caused by string concatenation.

There are only five:

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;

Escaping characters depends on where the special character is used.

<?xml version="1.0"?>
<valid>"'></valid>

The safe way is to escape all five characters in attributes, however, the > character needn't be escaped in attributes:

The ' character needn't be escaped in attributes if the quotes are ":

Likewise, the " needn't be escaped in attributes if the quotes are ':

<?xml version="1.0"?>
<valid attribute='"'/>
<?xml version="1.0"?>
<valid>
<!-- "'<>& -->
</valid>
<?xml version="1.0"?>
<valid>
<![CDATA["'<>&]]>
</valid>

All 5 special characters must not be escaped in XML processing instructions:

<?xml version="1.0"?>
<?process <"'&> ?>
<valid/>

@Pacerier, I beg you not to write your own XML/HTML escaping code. Use a library function or you're bound to miss a special case.

Also for line breaks you need to use and for tab, if you need these characters in an attribute.

If you're going to do a Find/Replace on these, just remember to do the replacement before the others.

From Wikipedia: "All permitted Unicode characters may be represented with a numeric character reference." So there are a lot more than 5.

escaping - What characters do I need to escape in XML documents? - Sta...

xml escaping character
Rectangle 27 9

Looks like you got an escape character

\ Is an escape character, you need to escape it too in this scenario. Otherwise, you'd get an unterminated string. \" means the actual character " rather than the start or an end of a string.

If you want the actual character \ you need to escape it too: \\

String[] man = new String[]{
              "|    |",
              "|    o",
              "|    |",
              "|   /|\\",  \\<- note the extra \
              "|    |",
              "|   / \\"   \\<- note the extra \ here too
             };

A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences (me: table in link)

This is of course in line with the language specification:

StringLiteral:
   "StringCharacters"

  StringCharacters:
   StringCharacter
   | StringCharacters StringCharacter

  StringCharacter:
   InputCharacter but not " or \
   | EscapeSequence


EscapeSequence:
    \ b    
    \ t   
    \ n   
    \ f   
    \ r    
    \ "   
    \ '  
    \ \  < -  **THIS IS THE ONE YOU HAD**
    OctalEscape   /* \u0000 to \u00ff: from octal value */

In computing and telecommunication, an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the judgement of whether something is an escape character or not depends on context.

C, C++, Java, and Ruby all allow exactly the same two backslash escape styles.

@MarounMaroun to avoid gaining rep that was percieved as undeserved by OP

@MarounMaroun It's a trivial question, as such I did not want rep for it. On the other hand it's something a lot of users know about so it got a lot of edits from a lot of different users fast - doing this allowed us to produce a fast high quality answer.

Java string array double quote error - Stack Overflow

java
Rectangle 27 59

using System;
using System.Security;

class Sample {
  static void Main() {
    string text = "Escape characters  < > & \" \'";
    string xmlText = SecurityElement.Escape(text);
//output:
//Escape characters  &lt; &gt; &amp; &quot; &apos;
    Console.WriteLine(xmlText);
  }
}

.net - Escape invalid XML characters in C# - Stack Overflow

c# .net xml escaping
Rectangle 27 9

You have to escape the backslash, so try this:

str = "Hello\\nWorld";

Here are more escaped characters in Javascript.

escaping - Javascript - How to show escape characters in a string? - S...

javascript escaping
Rectangle 27 59

using System;
using System.Security;

class Sample {
  static void Main() {
    string text = "Escape characters  < > & \" \'";
    string xmlText = SecurityElement.Escape(text);
//output:
//Escape characters  &lt; &gt; &amp; &quot; &apos;
    Console.WriteLine(xmlText);
  }
}

.net - Escape invalid XML characters in C# - Stack Overflow

c# .net xml escaping
Rectangle 27 73

Take a look at http://json.org/. It claims a bit different list of escaped characters than Chris proposed.

\"
\\
\/
\b
\f
\n
\r
\t
\u four-hex-digits

Pretty sure THIS should have been the answer...

Except that it's completely unclear which characters should be encoded with \uxxxx sequence...

\f

\uXXXX escape codes specify a code point in the Basic Multilingual Plane (U+0000 through U+FFFF). See the official specification "ECMA-404 The JSON Data Interchange Standard" for more information.

@Mugen: No, a int or a bool or a float can't contain { or }. And a string is always between double-quotes, so no confusion there, assuming of course your parser works correctly.

asp.net mvc - Where can I find a list of escape characters required fo...

asp.net-mvc json escaping
Rectangle 27 7

JavaScript uses the \ (backslash) as an escape characters for:

  • \v vertical tab (IE < 9 treats '\v' as 'v' instead of a vertical tab ('\x0B'). If cross-browser compatibility is a concern, use \x0B instead of \v.)
  • \0 null character (U+0000 NULL) (only if the next character is not a decimal digit; else its an octal escape sequence)

Note that the \v and \0 escapes are not allowed in JSON strings.

escaping - Javascript - How to show escape characters in a string? - S...

javascript escaping
Rectangle 27 27

You can use the regular expression syntax:

var programProductRegex = /[\s\/\)\(\w&-]/;

If you use the RegExp object constructor you need to pass in a string. Because backslashes are special escape characters inside JavaScript strings and they're also escape characters in regular expressions, you need to use two backslashes to do a regex escape inside a string. The equivalent code using a string would then be:

All the backslashes that were in the original regular expression need to be escaped in the string to be correctly interpreted as backslashes.

Of course the first option is better. The constructor is helpful when you obtain a string from somewhere and want to make a regular expression out of it.

var programProductRegex  = new RegExp(userInput);

yes, it's a delimiter

Note also that you do not need to escape() parentheses in a character class.

@ridgerunner: Yes, and neither the forward slashes, but I kept them to maintain consistency with the original pattern.

Nice tip with the double slashes. (boo for Javascript for being as annoying as Java in this regard)

JavaScript Regex, where to use escape characters? - Stack Overflow

javascript regex escaping
Rectangle 27 27

You can use the regular expression syntax:

var programProductRegex = /[\s\/\)\(\w&-]/;

If you use the RegExp object constructor you need to pass in a string. Because backslashes are special escape characters inside JavaScript strings and they're also escape characters in regular expressions, you need to use two backslashes to do a regex escape inside a string. The equivalent code using a string would then be:

All the backslashes that were in the original regular expression need to be escaped in the string to be correctly interpreted as backslashes.

Of course the first option is better. The constructor is helpful when you obtain a string from somewhere and want to make a regular expression out of it.

var programProductRegex  = new RegExp(userInput);

yes, it's a delimiter

Note also that you do not need to escape() parentheses in a character class.

@ridgerunner: Yes, and neither the forward slashes, but I kept them to maintain consistency with the original pattern.

Nice tip with the double slashes. (boo for Javascript for being as annoying as Java in this regard)

JavaScript Regex, where to use escape characters? - Stack Overflow

javascript regex escaping
Rectangle 27 27

You can use the regular expression syntax:

var programProductRegex = /[\s\/\)\(\w&-]/;

If you use the RegExp object constructor you need to pass in a string. Because backslashes are special escape characters inside JavaScript strings and they're also escape characters in regular expressions, you need to use two backslashes to do a regex escape inside a string. The equivalent code using a string would then be:

All the backslashes that were in the original regular expression need to be escaped in the string to be correctly interpreted as backslashes.

Of course the first option is better. The constructor is helpful when you obtain a string from somewhere and want to make a regular expression out of it.

var programProductRegex  = new RegExp(userInput);

yes, it's a delimiter

Note also that you do not need to escape() parentheses in a character class.

@ridgerunner: Yes, and neither the forward slashes, but I kept them to maintain consistency with the original pattern.

Nice tip with the double slashes. (boo for Javascript for being as annoying as Java in this regard)

JavaScript Regex, where to use escape characters? - Stack Overflow

javascript regex escaping
Rectangle 27 110

Take your JSON and .stringify() it. Then use the .replace() method and replace all occurrences of \n with \\n.

As far as I know of, there are no well-known JS libraries for escaping all special characters in a string. But, you could chain the .replace() method and replace all of the special characters like this:

But that's pretty nasty, isn't it? Enter the beauty of functions, in that they allow you to break code into pieces and keep the main flow of your script clean, and free of 8 chained .replace() calls. So let's put that functionality into a function called, escapeSpecialChars(). Let's go ahead and attach it to the prototype chain of the String object, so we can call escapeSpecialChars() directly on String objects.

String.prototype.escapeSpecialChars = function() {
    return this.replace(/\\n/g, "\\n")
               .replace(/\\'/g, "\\'")
               .replace(/\\"/g, '\\"')
               .replace(/\\&/g, "\\&")
               .replace(/\\r/g, "\\r")
               .replace(/\\t/g, "\\t")
               .replace(/\\b/g, "\\b")
               .replace(/\\f/g, "\\f");
};

Once we have defined that function, the main body of our code is as simple as this:

var myJSONString = JSON.stringify(myJSON);
var myEscapedJSONString = myJSONString.escapeSpecialChars();
// myEscapedJSONString is now ready to be POST'ed to the server

Thanks alex. I have to do this for all the escape characters right? Is there is any JS library to do this?

This is the exact function which solved my problem String.prototype.escapeSpecialChars = function() { return this.replace(/\\/g, "\\\\"). replace(/\n/g, "\\n"). replace(/\r/g, "\\r"). replace(/\t/g, "\\t"). replace(/\f/g, "\\f"). replace(/"/g,"\\\""). replace(/'/g,"\\\'"). replace(/\&/g, "\\&"); }

As noted in the answer by user667073, there are a few errors in this solution. See json.org - & and ' must not be escaped.

I had to down-vote this since the regular expressions seem to be wrong. I tried to use it, but had to fix the regular expressions by removing one of the slashes, for example: /\\n/g should be /\n/g. See "Non-Printable Characters" at this link for details - RegExp Info

escaping - How to escape a JSON string containing newline characters u...

javascript escaping
Rectangle 27 9

= inserts HTML with escaped characters. Example:

= javascript_include_tag("1", "2")

== inserts HTML without escaping. It is needed when you have already rendered HTML and you need to insert it to your layout directly. Example:

== render 'footer'

ruby on rails - Difference between single and double equals in Slim (=...

ruby-on-rails slim-lang
Rectangle 27 16

Like you, I have been looking into several comments and post to replace special escape characters in my JSON which contains html object inside that.

My object is to remove the special characters in JSON object and also render the html which is inside the json object.

Here is what I did and hope its very simple to use.

JSON.parse(JSON.stringify(jsonObject));

escaping - How to escape a JSON string containing newline characters u...

javascript escaping
Rectangle 27 171

You need to escape the string you are writing out into DoEdit to scrub out the double-quote characters. They are causing the onclick HTML attribute to close prematurely.

Using the JavaScript escape character, \, isn't sufficient in the HTML context. You need to replace the double-quote with the proper XML entity representation, .

Right, but wouldn't that be this? <a href="#" onclick="DoEdit('Preliminary Assessment \"Mini\"'); return false;">edit</a> I tried that, and it is still screwing up. This has got to be a simple WTF but for the life of me, I can't see it.

It's not a javascript issue, it's an HTML/XML encoding issue: you can't have double-quote characters inside an attributes value w/o escaping them... otherwise browsers/parsers think you're ending the attribute value declaration.

'mystring'.replace(/"/g, '&quot;');

in the previous comment there is an extra quote. The code that works is 'mystring'.replace(/'/g, '');

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

Escape quotes in JavaScript - Stack Overflow

javascript quotes escaping
Rectangle 27 7

The escape sequence for "Arrow up" is "\u001b[A". \u001b is the code for ESC (Escape).

That means while you have a single key code in JavaScript, you need to write 3 bytes to BASH to achieve the desired effect.

You can see it for yourself by typing Ctrl+VUp.

The Ctrl+V tells bash: "Don't try to interpret the next input; just insert it verbatim".

error: illegal escape character

If there is someone from Swift, the String is "\u{1b}[A"

java - "ASCII" codes for arrow up, down, left and right - Stack Overfl...

java jquery bash ascii