escaping

Can I escape braces in a java MessageFormat?

旧时模样 提交于 2019-11-29 05:23:44
I want to output some braces in a java MessageFormat. For example I know the following does not work: MessageFormat.format(" public {0} get{1}() {return {2};}\n\n", type, upperCamel, lowerCamel); Is there a way of escaping the braces surrounding "return {2}"? You can put them inside single quotes e.g. '{'return {2};'}' See here for more details. Bombe Wow. Surprise! The documentation for MessageFormat knows the answer: Within a String , "''" represents a single quote. A QuotedString can contain arbitrary characters except single quotes; the surrounding single quotes are removed. An

How do I replace a double-quote with an escape-char double-quote in a string using javascript?

与世无争的帅哥 提交于 2019-11-29 04:43:03
问题 Say I have a string variable ( var str ) as follows- Dude, he totally said that "You Rock!" Now If I'm to make it look like as follows- Dude, he totally said that \"You Rock!\" How do I accomplish this using the JavaScript replace() function? str.replace("\"","\\""); is not working so well. It gives unterminated string literal error. Now, if the above sentence were to be stored in a SQL database, say in MySQL as a LONGTEXT (or any other VARCHAR -ish) datatype, what else string optimizations I

What characters need to be escaped in .NET Regex?

随声附和 提交于 2019-11-29 04:42:51
问题 In a .NET Regex pattern, what special characters need to be escaped in order to be used literally? 回答1: I don't know the complete set of characters - but I wouldn't rely on the knowledge anyway, and I wouldn't put it into code. Instead, I would use Regex.Escape whenever I wanted some literal text that I wasn't sure about: // Don't actually do this to check containment... it's just a little example. public bool RegexContains(string haystack, string needle) { Regex regex = new Regex("^.*" +

Getting correct string length in Python for strings with ANSI color codes

烂漫一生 提交于 2019-11-29 03:09:05
I've got some Python code that will automatically print a set of data in a nice column format, including putting in the appropriate ASCII escape sequences to color various pieces of the data for readability. I eventually end up with each line being represented as a list, with each item being a column that is space-padded so that the same columns on each line are always the same length. Unfortunately when I actually go to print this, not all the columns line up. I suspect this is to do with the ASCII escape sequences - because the len function doesn't seem to recognize these: >>> a = '\x1b[1m0

Why is percentage character not escaped with backslash in C?

≯℡__Kan透↙ 提交于 2019-11-29 03:07:48
The printf() documentation says that if someone wants to print % in C, he can use: printf("%%") Why is it not: printf("\%") as with other special characters? Because the % is handled by printf . It is not a special character in C, but printf itself treats it differently. The backslash is processed by the compiler when interpreting the source text of the program. So the common result is that the source text "\%" produces a string containing ”%”. The format string is interpreted by the printf routine, so it processes the characters passed to it. By this time, the backslash is no longer present,

Escape double and single backslashes in a string in Ruby

懵懂的女人 提交于 2019-11-29 02:57:12
问题 I'm trying to access a network path in my ruby script on a windows platform in a format like this. \\servername\some windows share\folder 1\folder2\ Now If I try to use this as a path, it won't work. Single backslashes are not properly escaped for this script. path = "\\servername\some windows share\folder 1\folder2\" d = Dir.new(path) I tried everything I could think of to properly escape slashes in the path. However I can't escape that single backslash - because of it's special meaning. I

How to prevent auto escape in Django templates?

孤街醉人 提交于 2019-11-29 02:47:49
问题 In the docs it says: The only exceptions are variables that are already marked as “safe” from escaping, either by the code that populated the variable, or because it has had the safe or escape filters applied." How does the "populated the variable" part work ? I'm actually looking for a way to declare a template tag as safe in the view. I somehow think it's not a good idea to let a designer decide. My co-worker will just add it whenever she 'thinks' it's a good idea. https://docs

How to include an ampersand (&) in the content of a ComboBoxItem

穿精又带淫゛_ 提交于 2019-11-29 02:47:22
I currently have a Combobox like the following: //XAML <ComboBox> <ComboBoxItem> Awake & Alive</ComboBoxItem> </ComboBox> This raises an error: Entity references or sequences beginning with an ampersand '&' must be terminated with a semicolon ';'. I assume I am missing an escape sequence of some sort to allow me to use a &. How can I set the content of this comboboxitem to include a &? Use & to encode the ampersand. //XAML <ComboBox> <ComboBoxItem> Awake & Alive</ComboBoxItem> </ComboBox> The short answer is to use & to encode an ampersand. See also Entities: Handling Special Content on XML

Escaping characters in JavaScript single and double quotes [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-11-29 02:30:25
This question already has an answer here: Double quote in JavaScript string 4 answers I've got a question about escaping characters in JavaScript that I'm hoping you may be able to help with. Say if I have the following JavaScript code: document.write("<img src=\"http://www.google.com\" />"); Now in the example above, you can see that I have begun the document.write with double quotes " and hence why I need to escape the quotes within the < img src="" /> to ensure that JavaScript still thinks that it's a string. But in the below example you can see I have used a single quote ' to begin the

Java Regex for matching quoted string with escaped quotes

眉间皱痕 提交于 2019-11-29 02:24:16
I know there are already many questions like mine but I found no answer which works in Java. So I write a new question. I have text files with content like this: key1 = "This is a \"test\" text with escapes using '\\' characters"; key2 = 'It must work with \'single\' quotes and "double" quotes'; I need a regular expression which matches the values in the double-quotes (or single-quotes). This regular expression must support the escaped quotes and escaped backslashes. The regular expression must work with Java standard Pattern/Matcher classes. Try this regular expression: '([^\\']+|\\([btnfr"'\