Cadena de escape usando 'Estoy feliz' - ¿término técnico para eso?

If I have a String I'm happy and I like to use it in a string that uses single quotation marks ('), then I need to escape the quotation mark in the string.

In most of the time this is done by doing something I call "backslash escape": Just prefix the quotation mark with a backslash: 'I\'m happy'. Other people seem to do this too: If I enter "backslash escape" on google lots of pages show up that explain the technique. Descriptive term, perfect.

But for example in SQL you'd write 'I''m happy'. Is there a term for that? How to call that? Judging by google search results "repeat-the-quotation-mark-escape" is very unpopular: It just gives a bunch of unrelated stuff.

EDIT: Reading from the comments I believe I need to explain more why I am asking:

My current Java code has a method that escape strings using the mentioned principle. I need to give the method a descriptive name. Of course I could call it "sqlEscape", but it's not really the invention of SQL... Just calling the method plain "escape" does not give any hints on exactly how the method escapes the string...

preguntado el 22 de mayo de 12 a las 17:05

escaping is a general term - its meaning and implementation is context-specific. The fact that a backslash is often used to achieve this does not make 'backslash escaping' correcta. in HTML or (as you note) SQL this is not the case. -

I believe the general term is "escape sequence". -

Its "no-mouth escape" because '' seems like a person with no mouth. -

How about ‘encoding’ or ‘quoting’? -

The escaping that you need to accomplish is for the purpose of using the data with SQL, and your method name can communicate "why" in the absence of a precisely stated "what." It's a little heretical to say it, but I would call your method escapeForSQL(). -

1 Respuestas

The escaping that you need to accomplish is for the purpose of using the data with SQL. In the absence of a good word for the "what," my opinion (somewhat heretical) is that your method name can communicate the "why." So a method named escapeForSQL() would be acceptable to me.

Of course, all we're really doing is doubling the single quotes; we're not doing any other escaping. So doubleUpTicks() or doubleUpSingleQuotes() would work for me, too.

contestado el 22 de mayo de 12 a las 19:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.