backslash

String replace with backslashes in Python

北战南征 提交于 2019-12-06 08:19:41
I'm trying to do a simple replacement of " " with "\s" (the literal \s, not some sort of backslash escape). This is what I think should happen: >>> 'asdf hjkl'.replace(' ', '\s') 'asdf\shjkl' I did this: >>> 'asdf hjkl'.replace(' ', '\s') 'asdf\\shjkl' >>> 'asdf hjkl'.replace(' ', '\\s') 'asdf\\shjkl' Neither returns what I expected, and I can't for the life of me understand what's going on. What input do I have to use to get my expected output? You're getting what you want. It just doesn't look that way in the REPL: >>> 'asdf hjkl'.replace(' ', '\s')[4] '\\' As you can see, that's one

Check if string containts slash or backslash in Bash?

霸气de小男生 提交于 2019-12-05 12:18:08
I'm currently trying to get my bash script checking if a string containts a "/" or a "\" but somehow I can't get it working. Here is what I got so far: if [[ "$1" == *\/* ]]; then ... elif if [[ "$1" == *\\* ]]; then ... fi Help is much appreciated! Thanks This checks if either \ or / are in the variable $string . if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]] then echo "yes" fi Test: $ string="hello" $ if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]]; then echo "yes"; fi $ $ string="hel\lo" $ if [[ "$string" == *\/* ]] || [[ "$string" == *\\* ]]; then echo "yes"; fi yes $ string=

What's the Magic Behind Escape(\\) Character

馋奶兔 提交于 2019-12-05 10:03:39
How does the C/C++ compiler manipulate the escape character ["\"] in source code? How is compiler grammar written for processing that character? What does the compiler do after encountering that character? Most compilers are divided into parts: the compiler front-end is called a lexical analyzer or a scanner. This part of the compiler reads the actual characters and creates tokens. It has a state machine which decides, upon seeing an escape character, whether it is genuine (for example when it appears inside a string) or it modifies the next character. The token is output accordingly as the

MySQL PHP Escape String '\\' - Why is it not saved in the database with the backslash?

混江龙づ霸主 提交于 2019-12-05 07:23:52
Confused about escape string and how it is stored in the database In my MySQL call, I escaping a string with a backslash: UPDATE `TABLE` SET `PERSONAL_BELONGINGS` = 'Tom\'s things' But when I look in the phpadmin - the value was saved like this: |Tom's things| Why is the backslash not saved into the database? This causes problems when I read this value into javascript and then try passing it around - my javascript strings will terminate. This is why I escaped the character to begin with. Why is MySQL removing the '\' backslash before it is saved into the database? If not saving it in the

Why does PyCharm use double backslash to indicate escaping?

馋奶兔 提交于 2019-12-04 07:54:07
For instance, I write a normal string and another "abnormal" string like this: Now I debug it, finding that in the debug tool, the "abnormal" string will be shown like this: Here's the question: Why does PyCharm show double backslashes instead of a single backslash? As is known to all, \' means ' . Is there any trick? What I believe is happening is the ' in your c variable string needs to be escaped and PyCharm knows this at runtime, given you have surrounded the full string in " (You'll notice in the debugger, your c string is now surrounded by ' ). To escape the single quote it changes it to

NSString Backslash escaping

对着背影说爱祢 提交于 2019-12-04 04:30:06
问题 I am working on an iPhone OS application that sends an xml request to a webservice. In order to send the request, the xml is added to an NSString. When doing this I have experienced some trouble with quotation marks " and backslashes \ in the xml file, which have required escaping. Is there a complete list of characters that need to be escaped? Also, is there an accepted way of doing this escaping (ie replacing \ with \\ and " with \" ) or is it a case of creating a method myself? Thanks 回答1:

Path with backslashes to path with forward slashes javascript

匆匆过客 提交于 2019-12-04 00:11:10
问题 I'm trying to make a local xml file parsing "application" for some colleagues and i'm using the current function to retrieve the files: function ShowFolderFileList(folderspec) { var fso, f, f1, fc, s; fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.GetFolder(folderspec); fc = new Enumerator(f.files); s = ""; for (; !fc.atEnd(); fc.moveNext()) { var pathString = fc.item(); $("#test").append(pathString + "<br />"); } } The problem with this function it returns a string similar to

Java replace issues with ' (apostrophe/single quote) and \ (backslash) together

喜你入骨 提交于 2019-12-03 02:22:09
问题 I seem to be having issues. I have a query string that has values that can contain single quotes. This will break the query string. So I was trying to do a replace to change ' to \' . Here is a sample code: "This is' it".replace("'", "\'"); The output for this is still: "This is' it". It thinks I am just doing an escape character for the quote. So I tried these two pieces of code: "This is' it".replace("'", "\\'"); // \\ for the backslash, and a ' char "This is' it".replace("'", "\\\'"); // \

Java replace issues with ' (apostrophe/single quote) and \\ (backslash) together

橙三吉。 提交于 2019-12-02 15:52:51
I seem to be having issues. I have a query string that has values that can contain single quotes. This will break the query string. So I was trying to do a replace to change ' to \' . Here is a sample code: "This is' it".replace("'", "\'"); The output for this is still: "This is' it". It thinks I am just doing an escape character for the quote. So I tried these two pieces of code: "This is' it".replace("'", "\\'"); // \\ for the backslash, and a ' char "This is' it".replace("'", "\\\'"); // \\ for the backslash, and \' for the ' char Both of the above STILL results in the same output: "This is

usage of “\” in C?

拈花ヽ惹草 提交于 2019-12-02 15:23:37
问题 I was looking over this code, but i was unable to figure out why the usage of "\" after the && operator? if ((*(u32*)(kaddr + 0x64) == *(u32*)(kaddr + 0x78)) && \ (*(u32*)(kaddr + 0x68) == *(u32*)(kaddr + 0x88))) 回答1: The \ right before the end of the line glues the following line to the current. Since C normally ignores whitespace, this is mostly useful when declaring macros. 回答2: The backslash is not needed, unless this is part of a #define . From the C specification §5.1.1.2 Each instance