escaping

Interpret escape characters in single quoted string

佐手、 提交于 2019-12-18 02:47:12
问题 Having a single-quoted string: $content = '\tThis variable is not set by me.\nCannot do anything about it.\n'; I would like to inerpret/process the string as if it was double-quoted . In other words I would like to replace all the possible escape characters (not just tab and linefeed as in this example) with the real values, taking into account that backslash might be escaped as well, thus '\\n' needs to be replaced by '\n'. eval() would easily do what I need but I cannot use it. Is there

Escape tags in html

安稳与你 提交于 2019-12-18 01:29:08
问题 What are escape tags in html? Are they " < > to represent " < > ? And how do these work? Is that hex, or what is it? How is it made, and why aren't they just the characters themselves? 回答1: How do these work? Anything &#num; is replaced with character from ASCII table, matching that num . Is that hex, or what is it? It's not hex, the number represents characters number in decimal in ASCII table. Check out ASCII table. Check Dec and HTML columns. Why aren't they just the characters themselves?

What's the Use of '\r' escape sequence?

孤人 提交于 2019-12-18 01:19:12
问题 I have C code like this: #include<stdio.h> int main() { printf("Hey this is my first hello world \r"); return 0; } I have used the \r escape sequence as an experiment. When I run the code I get the output as: o world Why is that, and what is the use of \r exactly? If I run the same code in an online compiler I get the output as: Hey this is my first hello world Why did the online compiler produce different output, ignoring the \r ? 回答1: \r is a carriage return character; it tells your

Use jq to parse a JSON String

扶醉桌前 提交于 2019-12-17 23:15:33
问题 I'm trying to get jq to parse a JSON structure like: { "a" : 1, "b" : 2, "c" : "{\"id\":\"9ee ...\",\"parent\":\"abc...\"}\n" } That is, an element in the JSON is a string with escaped json. So, I have something along the lines of $ jq [.c] myFile.json | jq [.id] But that crashes with jq: error: Cannot index string with string This is because the output of .c is a string, not more JSON. How do I get jq to parse this string? My initial solution is to use sed to replace all the escape chars ( \

In Java, should I escape a single quotation mark (') in String (double quoted)?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 22:27:12
问题 In Java, \' denotes a single quotation mark (single quote) character, and \" denotes a double quotation mark (double quote) character. So, String s = "I\'m a human."; works well. However, String s = "I'm a human." does not make any compile errors, either. Likewise, char c = '\"'; works, but char c = '"'; also works. In Java, which is better to use? In HTML or CSS, things like style="font-family:'Arial Unicode MS';" are more often (and for such tags, I think it's the only way to use quotation

python IDLE shell appears not to handle some escapes correctly

一笑奈何 提交于 2019-12-17 21:37:02
问题 For example \b backspace prints as quad (shown as [] in example below). But \n newline is Ok. >>> print 'abc\bd' abc[]d >>> print 'abc\nd' abc d Im running under Vista (pro), python 2.7 Ive tried googling this issue generally and in SO and cant find anything relevant, which seems odd and makes me wonder if theres some setting or other may be wrong in my setup. Not sure what to look for. 回答1: What am I doing wrong or what should I be looking for? Is it reasonable to expect backspace,

Jsoup unescapes special characters

折月煮酒 提交于 2019-12-17 21:03:20
问题 I'm using Jsoup to remove all the images from an HTML page. I'm receiving the page through an HTTP response - which also contains the content charset. The problem is that Jsoup unescapes some special characters. For example, for the input: <html><head></head><body><p>isn’t</p></body></html> After running String check = "<html><head></head><body><p>isn’t</p></body></html>"; Document doc = Jsoup.parse(check); System.out.println(doc.outerHtml()); I get: <html><head></head><body><p>isn’t</p><

Removing backslashes from a string in Python

大城市里の小女人 提交于 2019-12-17 21:00:46
问题 How do I remove all the backslashes from a string in Python? This is not working for me: result = result.replace("\\", result) Do I need to treat result as a raw string? 回答1: Your code is saying to replace each instance of '\' with result . Have you tried changing it to result.replace("\\", "") ? 回答2: Use decode('string_escape') , for example: result = stringwithbackslashes.decode('string_escape') string_escape : Produce a string that is suitable as string literal in Python source code or

PatternSyntaxException while trying to split by },{

余生长醉 提交于 2019-12-17 20:19:41
问题 I am trying to break up an array I got through an API on a site, which Java has retrieved as a String . String[] ex = exampleString.split("},{"); A PatternSyntaxException is thrown. For some reason, it really doesn't like },{ . I have tried escaping it as \{ , but it says it is an illegal escape. What is the proper way to escape this string? 回答1: For some reason, it really doesn't like },{. This is because braces ( } and { ) are special characters in Java regular expressions. If you try to

Passing meta-characters to Python as arguments from command line

佐手、 提交于 2019-12-17 20:07:49
问题 I'm making a Python program that will parse the fields in some input lines. I'd like to let the user enter the field separator as an option from the command line. I'm using optparse to do this. I'm running into the problem that entering something like \t will separate literally on \t , rather than on a tab, which is what I want. I'm pretty sure this is a Python thing and not the shell, since I've tried every combo of quotes, backslashes, and t 's that I can think of. If I could get optparse