Questions tagged [escaping]

Escaping is the process of applying an alternate meaning to a character or set of characters.

Escaping is used for many purposes, such as providing representations of unprintable characters, changing font colors in terminals, or allowing the inclusion in a string of a character normally used to terminate the string, as well as allowing to output a character to user when that character can be used as a control or markup character.

Some of the more common uses of escaping

  • URL encoding to allow including characters such as / or ?, and others, in URL queries;
  • XML and HTML entities that can be used to encode special characters that, for example, would normally be used for markup purposes.
8255 questions
205
votes
16 answers

Can I convert a C# string value to an escaped string literal

In C#, can I convert a string value to a string literal, the way I would see it in code? I would like to replace tabs, newlines, etc. with their escape sequences. If this code: Console.WriteLine(someString); produces: Hello World! I want this…
Hallgrim
  • 14,210
  • 10
  • 40
  • 54
200
votes
4 answers

Properly escape a double quote in CSV

I have a line like this in my CSV: "Samsung U600 24"","10000003409","1","10000003427" Quote next to 24 is used to express inches, while the quote just next to that quote closes the field. I'm reading the line with fgetcsv but the parser makes a…
srgb
  • 3,785
  • 6
  • 22
  • 44
196
votes
5 answers

How do I escape a single quote ( ' ) in JavaScript?

UPDATE: I want to give an updated answer to this question. First, let me state if you're attempting to accomplish what I have below, I recommend that you manage events by adding event listeners instead. I highly recommend that you utilize jQuery for…
Matthew
  • 2,887
  • 3
  • 14
  • 27
195
votes
6 answers

Escape single quote character for use in an SQLite query

I wrote the database schema (only one table so far), and the INSERT statements for that table in one file. Then I created the database as follows: $ sqlite3 newdatabase.db SQLite version 3.4.0 Enter ".help" for instructions sqlite> .read…
jpm
  • 16,162
  • 33
  • 60
  • 66
195
votes
5 answers

PHP sprintf escaping %

I want the following output:- About to deduct 50% of € 27.59 from your Top-Up account. when I do something like this:- $variablesArray[0] = '€'; $variablesArray[1] = 27.59; $stringWithVariables = 'About to deduct 50% of %s %s from your Top-Up…
Sandeepan Nath
  • 8,771
  • 17
  • 66
  • 131
192
votes
11 answers

How to escape @ characters in Subversion managed file names?

For many Subversion operations, appending the '@' symbol to the end of a file or URL argument allows you to target a specific revision of that file. For example, "svn info test.txt@1234" will give information about test.txt as it existed in…
weston
  • 2,848
  • 3
  • 21
  • 23
190
votes
6 answers

How can you escape the @ character in javadoc?

How can I escape the @ symbol in javadoc? I am trying to use it inside a {@code} tag, which is inside
 tags.
I already tried the html escape @ sequence, but that didn't work.
JayL
  • 2,509
  • 4
  • 19
  • 15
188
votes
17 answers

HtmlSpecialChars equivalent in Javascript?

Apparently, this is harder to find than I thought it would be. And it even is so simple... Is there a function equivalent to PHP's htmlspecialchars built into Javascript? I know it's fairly easy to implement that yourself, but using a built-in…
Bart van Heukelom
  • 40,403
  • 57
  • 174
  • 291
180
votes
16 answers

How to escape a JSON string containing newline characters using JavaScript?

I have to form a JSON string in which a value is having new line character. This has to be escaped and then posted using AJAX call. Can any one suggest a way to escape the string with JavaScript. I am not using jQuery.
Srikant
  • 1,823
  • 2
  • 12
  • 5
174
votes
4 answers

How do I escape double quotes in attributes in an XML String in T-SQL?

Pretty simple question - I have an attribute that I would like to have double quotes in. How do I escape them? I've tried \" "" \\" And I've made the @xml variable both xml type and varchar(max) for all of them. declare @xml xml --(or…
Tom Ritter
  • 94,954
  • 29
  • 130
  • 168
174
votes
5 answers

Why shouldn't `'` be used to escape single quotes?

As stated in, When did single quotes in HTML become so popular? and Jquery embedded quote in attribute, the Wikipedia entry on HTML says the following: The single-quote character ('), when used to quote an attribute value, must also be escaped as…
brad
  • 67,670
  • 21
  • 67
  • 84
165
votes
2 answers

Is there a PHP function that can escape regex patterns before they are applied?

Is there a PHP function that can escape regex patterns before they are applied? I am looking for something along the lines of the C# Regex.Escape() function.
vfclists
  • 16,968
  • 18
  • 63
  • 88
162
votes
10 answers

How to escape apostrophe (') in MySql?

The MySQL documentation says that it should be \'. However, both scite and mysql shows that '' works. I saw that and it works. What should I do?
user4951
  • 29,779
  • 47
  • 157
  • 270
160
votes
11 answers

Escaping ampersand character in SQL string

I am trying to query a certain row by name in my sql database and it has an ampersand. I tried to set an escape character and then escape the ampersand, but for some reason this isn't working and I'm uncertain as to what exactly my problem is. Set…
Slater Victoroff
  • 19,762
  • 18
  • 78
  • 135
159
votes
18 answers

How should I escape strings in JSON?

When creating JSON data manually, how should I escape string fields? Should I use something like Apache Commons Lang's StringEscapeUtilities.escapeHtml, StringEscapeUtilities.escapeXml, or should I use java.net.URLEncoder? The problem is that when I…
βξhrαng
  • 41,698
  • 21
  • 103
  • 145