escaping

How to decode a string containing backslash-encoded Unicode characters?

不羁的心 提交于 2019-12-10 15:59:30
问题 I have a string stored as a : a := `M\u00fcnchen` fmt.Println(a) // prints "M\u00fcnchen" b := "M\u00fcnchen" fmt.Println(b) // prints "München" Is there a way I can convert a into b ? 回答1: You can use strconv.Unquote for this: u := `M\u00fcnchen` s, err := strconv.Unquote(`"` + u + `"`) if err != nil { // .. } fmt.Printf("%v\n", s) Outputs: München 来源: https://stackoverflow.com/questions/35519106/how-to-decode-a-string-containing-backslash-encoded-unicode-characters

How can I interpret escape sequences in a multiline scala string?

不羁岁月 提交于 2019-12-10 15:58:24
问题 In a nutshell: """I want to be able to |have the convenient formatting of a multiline string, |while using inline escape sequences\r\r\b\\ | |How can this be done?""".stripMargin 回答1: Two options that I can think of: You can use StringContext.treatEscapes directly: StringContext.treatEscapes("""I want to be able to |have the convenient formatting of a multiline string, |while using inline escape sequences\r\r\b\\ | |How can this be done?""".stripMargin) If the variable substitution feature of

Pass shell-escaped string of arguments to a subcommand in Bourne shell

若如初见. 提交于 2019-12-10 15:37:54
问题 Say I have a command I want to run ( cmd ) and a variable containing the arguments I want to pass to the function (something like --foo 'bar baz' qux ). Like so: #!/bin/sh command=cmd args="--foo 'bar baz' qux" The arguments contain quotes, like the ones shown above, that group together an argument containing a space. I'd then like to run the command: $command $args This, of course, results in running the command with four arguments: --foo , 'bar , baz' , and qux . The alternative I'm used to

Encode a String to be used as shell argument

可紊 提交于 2019-12-10 15:26:58
问题 I need to use a name of file as an argument in linux shell command. The problem is, java gives me that name as it is, saving all that spaces and other characters, and thus shell complains. Is there a method to escape all those problematic characters before passing the string to shell? 回答1: You should be able to put single quotes around the argument and avoid escaping it altogether. Will that work for you? Old: myapp -f /bad/path/to/file New: myapp -f '/good/path/to/file' 回答2: Had the same

Escaping ampersands in URLs for HttpClient requests

核能气质少年 提交于 2019-12-10 15:06:11
问题 So I've got some Java code that uses Jakarta HttpClient like this: URI aURI = new URI( "http://host/index.php?title=" + title + "&action=edit" ); GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery()); The problem is that if title includes any ampersands (&), they're considered parameter delimiters and the request goes screwy... and if I replace them with the URL-escaped equivalent %26 , then this gets double-escaped by getEscapedPathQuery() into %2526 . I'm currently working around

what does \ do on non escape characters?

本秂侑毒 提交于 2019-12-10 14:48:29
问题 I asked another question poorly so i'll ask something else. According to http://www.c-point.com/javascript_tutorial/special_characters.htm there are a few escape characters such as \n and \b. However / is not one of them. What happens in this case? ( \/ ) is the \ ignored? I have a string in javascript 'http:\/\/www.site.com\/user' . Not that this is a literal with ' so with " it would look like \\/ anyways i would like to escape this string thus the question on what happens on non 'special'

Echo exact string in windows batch file?

半城伤御伤魂 提交于 2019-12-10 14:42:01
问题 I'm trying to echo a string stored in a variable but it seems to require a lot of escaping. I'm trying with the following code: setlocal EnableDelayedExpansion @echo off set "grass=@##&!$^&%**(&)" echo !grass! I want to echo the variable grass verbatim so I see a @##&!$^&%**(&) in the output. What should be done? Thanks! 回答1: echo !grass! will always echo the current value verbatim, without the need of any escaping. Your problem is, the value is not what you think it is! The problem is

Javascript: Regex to escape parentheses and spaces

别说谁变了你拦得住时间么 提交于 2019-12-10 14:31:22
问题 Looking to backslash escape parentheses and spaces in a javascript string. I have a string: (some string) , and I need it to be \(some\ string\) Right now, I'm doing it like this: x = '(some string)' x.replace('(','\\(') x.replace(')','\\)') x.replace(' ','\\ ') That works, but it's ugly. Is there a cleaner way to go about it? 回答1: you can do this: x.replace(/(?=[() ])/g, '\\'); (?=...) is a lookahead assertion and means 'followed by' [() ] is a character class. 回答2: Use a regular expression,

Escaping a single quote when using JdbcTemplate

这一生的挚爱 提交于 2019-12-10 14:29:57
问题 We're using JdbcTemplate to modify our underlying Oracle database. We're doing this by way of the update(String sql) method. The code looks somehow like the following: String name = "My name's yellow"; String sql = "update FIELD set NAME = '" + name "' where ID = 10 jdbcTemplate.update(sql); This causes the error: java.sql.SQLException: ORA-00933: SQL command not properly ended The problem is the unescaped ' in the name variable. What's the most convenient and correct way to escape this

What does the \? (backslash question mark) escape sequence mean?

我的梦境 提交于 2019-12-10 14:24:17
问题 I'm writing a regular expression in Objective-C. The escape sequence \w is illegal and emits a warning, so the regular expression /\w/ must be written as @"\\w" ; the escape sequence \? is valid, apparently, and doesn't emit a warning, so the regular expression /\?/ must be written as @"\\?" (i.e., the backslash must be escaped). Question marks aren't invisible like \t or \n , so why is \? a valid escape sequence? Edit: To clarify, I'm not asking about the quantifier, I'm asking about a