backslash

Replace “\\” with “\” in a string in C#

℡╲_俬逩灬. 提交于 2019-11-26 01:54:28
问题 I still don\'t get how to do this. I saw many posts regarding this, but none of the solutions worked for me. I have a string called \"a\\\\b\". The result I need is \"a\\b\". How is this done? I have a text file which has a database connection string pointing to an instance called - Server\\DbInstance My aim is to do a string replace in the text file -- replace \"Server\\DbInstance\" with another value, say \"10.11.12.13, 1200\". So I have: stringToBeReplaced = @\"Server\\DbInstance\";

How can I use backslashes (\) in a string?

寵の児 提交于 2019-11-26 01:30:04
问题 I tried many ways to get a single backslash from an executed (I don\'t mean an input from html ). I can get special characters as tab, new line and many others then escape them to \\\\t or \\\\n or \\\\(someother character) but I cannot get a single backslash when a non-special character is next to it. I don\'t want something like: str = \"\\apple\"; // I want this, to return: console.log(str); // \\apple and if I try to get character at 0 then I get a instead of \\ . 回答1: (See ES2015 update

Escaping Strings in JavaScript

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 00:59:31
问题 Does JavaScript have a built-in function like PHP\'s addslashes (or addcslashes ) function to add backslashes to characters that need escaping in a string? For example, this: This is a demo string with \'single-quotes\' and \"double-quotes\". ...would become: This is a demo string with \\\'single-quotes\\\' and \\\"double-quotes\\\". 回答1: http://locutus.io/php/strings/addslashes/ function addslashes( str ) { return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); } 回答2: You

String.replaceAll single backslashes with double backslashes

北城以北 提交于 2019-11-25 23:40:17
问题 I\'m trying to convert the String \\something\\ into the String \\\\something\\\\ using replaceAll , but I keep getting all kinds of errors. I thought this was the solution: theString.replaceAll(\"\\\\\", \"\\\\\\\\\"); But this gives the below exception: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1 回答1: The String#replaceAll() interprets the argument as a regular expression. The \ is an escape character in both String and regex . You need to double-escape it

How to escape backslashes in R string

此生再无相见时 提交于 2019-11-25 23:28:54
问题 I\'m writing strings to a file using R: > x1=\"\\\\str\" > x2=\"\\\\\\str\" Error: \'\\s\' is an unrecognized escape in character string starting \"\\\\\\s\" > x2=\"\\\\\\\\str\" > write(file=\'test\',c(x1,x2)) When I open the file named test , I see this: \\str \\\\str If I want to get a string containing 5 backslashes, should I write 10 backslashes, like this? x=\"\\\\\\\\\\\\\\\\\\\\str\" 回答1: [...] If I want to get a string containing 5 \ ,should i write 10 \ [...] Yes, you should. To

Why do backslashes appear twice?

十年热恋 提交于 2019-11-25 22:20:53
问题 When I create a string containing backslashes, they get duplicated: >>> my_string = \"why\\does\\it\\happen?\" >>> my_string \'why\\\\does\\\\it\\\\happen?\' Why? 回答1: What you are seeing is the representation of my_string created by its __repr__() method. If you print it, you can see that you've actually got single backslashes, just as you intended: >>> print(my_string) why\does\it\happen? The string below has three characters in it, not four: >>> 'a\\b' 'a\\b' >>> len('a\\b') 3 You can get

Escaping Strings in JavaScript

无人久伴 提交于 2019-11-25 21:57:05
Does JavaScript have a built-in function like PHP's addslashes (or addcslashes ) function to add backslashes to characters that need escaping in a string? For example, this: This is a demo string with 'single-quotes' and "double-quotes". ...would become: This is a demo string with \'single-quotes\' and \"double-quotes\". Paolo Bergantino http://locutus.io/php/strings/addslashes/ function addslashes( str ) { return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); } Storm You can also try this for the double quotes: JSON.stringify(sDemoString).slice(1, -1); JSON.stringify('my