backslash

Need to select only data that contains backslashes in MySQL

僤鯓⒐⒋嵵緔 提交于 2019-11-29 14:00:45
I'm attempting to correct entries in a database that have been double-escaped. I believe magic_quotes was on while mysql_real_escape_string was being used. The double-escaping has caused some search results to be incorrect/missing. I've turned magic_quotes off and am planning to search for entries with a backslash and update them to remove any double-escaping. Trouble is, when I perform a query to search for entries with backslashes, I always get no results. SELECT title FROM exampletable WHERE title LIKE '%\\\\%' I'm using '%\\\\%' as recommended here: http://dev.mysql.com/doc/refman/5.0/en

python replace backslashes to slashes

岁酱吖の 提交于 2019-11-29 13:43:56
How can I escape the backslashes in the string: 'pictures\12761_1.jpg' ? I know about raw string. How can I convert str to raw if I take 'pictures\12761_1.jpg' value from xml file for example? You can use the string .replace() method. >>> print r'pictures\12761_1.jpg'.replace("\\", "/") pictures/12761_1.jpg You can also use split/join: print "/".join(r'pictures\12761_1.jpg'.split("\\")) EDITED: The other way you may use is to prepare data during it's retrieving(e.g. the idea is to update string before assign to variable) - for example: f = open('c:\\tst.txt', "r") print f.readline().replace('\

How to handle backslash character in PowerShell -replace string operations?

淺唱寂寞╮ 提交于 2019-11-29 13:16:52
I am using -replace to change a path from source to destination. However I am not sure how to handle the \ character. For example: $source = "\\somedir" $dest = "\\anotherdir" $test = "\\somedir\somefile" $destfile = $test -replace $source, $dest After this operation, $destfile is set to "\\\anotherdir\somefile" What is the correct way to do this to avoid the triple backslash in the result? Try the following: $source = "\\\\somedir" You were only matching 1 backslash when replacing, which gave you the three \\\ at the start of your path. The backslash is a regex escape character so \\ will be

Replacing single backslashes with double backslashes in php

人盡茶涼 提交于 2019-11-29 12:58:33
I came across a strange problem in my PHP programming. While using the backtrace function to get the last file the PHP compiler was working with. It would give it to me the path using backslashes. I wanted to store this string in the database, but MySQL would remove them; I'm assuming it was thinking I wanted to escape them. So C:\Path\To\Filename.php would end up C:PathToFileName.php in the database. When I posted this question to Google, I found many others with the same problem but in many different situations. People always suggested something like: $str = '\dada\dadda'; var_dump(str

Why I need to double-escape (use 4 \\) to find a backslash ( \\ ) in pure SQL?

[亡魂溺海] 提交于 2019-11-29 11:22:28
I do not understand this MySQL behaviour : if I want to display a\b, I can just select "a\\b" which work without problem : mysql> select "a\\b"; +-----+ | a\b | +-----+ | a\b | +-----+ 1 row in set (0.05 sec) But if I wnat to search a string containing a \ in a table using LIKE, I need to double-escape my "\". Why ? Here is an example. We prepare a small table. create table test ( test varchar(255) ); insert into test values ( "a\\b" ) , ( "a\\b\\c" ) , ( "abcd" ); mysql> select * from test; +-------+ | test | +-------+ | a\b | | a\b\c | | abcd | +-------+ 3 rows in set (0.05 sec) We try to

Replace single backslash with double backslash

随声附和 提交于 2019-11-29 09:11:00
It seems simple enough, right? Well, I don't know. Here's the code I'm trying: input = Regex.Replace(input, "\\", "\\\\\\"); However, I'm receiving an error, ArgumentException was unhandled - parsing "\" - Illegal \ at end of pattern. How do I do this? The first one should be "\\\\" , not "\\" . It works like this: You have written "\\" . This translates to the sequence \ in a string. The regex engine then reads this, which translates as backslash which isn't escaping anything, so it throws an error. With regex, it's much easier to use a "verbatim string". In this case the verbatim string

sh read command eats slashes in input?

∥☆過路亽.° 提交于 2019-11-29 09:06:41
Perhaps easiest to explain with an example: $ echo '\&|' \&| $ echo '\&|' | while read in; do echo "$in"; done &| It seems that the "read" command is interpreting the slashes in the input as escapes and is removing them. I need to process a file line by line without changing its contents and I'm not sure how to stop read from being smart here. Any ideas? Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may

Replacing double backslashes with single backslash

末鹿安然 提交于 2019-11-29 08:00:32
I have a string "\\u003c", which belongs to UTF-8 charset. I am unable to decode it to unicode because of the presence of double backslashes. How do i get "\u003c" from "\\u003c"? I am using java. I tried with, myString.replace("\\\\", "\\"); but could not achieve what i wanted. This is my code, String myString = FileUtils.readFileToString(file); String a = myString.replace("\\\\", "\\"); byte[] utf8 = a.getBytes(); // Convert from UTF-8 to Unicode a = new String(utf8, "UTF-8"); System.out.println("Converted string is:"+a); and content of the file is \u003c Not sure if you're still looking for

Why do backslashes disappear when run through echo?

こ雲淡風輕ζ 提交于 2019-11-29 07:20:52
I have code like this, which processes a CSV file: #!/bin/bash while read line do variable=$(echo $line | awk -F, '{print $2}') echo $variable done < ./file.csv If the CSV file contains any \ , when I run this command, the output text does not show the \ . How can I ensure that \ is not deleted? The reason for this behaviour is that the read builtin uses \ as escape character. The -r flag disables this behaviour. So, this should work: while read -r line variable=$(echo $line | awk -F, '{print $2}') echo $variable done < ./file.csv You should also place "..." around things like $(...) and

Why do I have to use double backslashes for file-paths in code?

徘徊边缘 提交于 2019-11-29 06:48:41
In my program I'm trying to open a file, for example C:\unescaped\backslashes.txt , but it fails to open! Why? What is this? This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining it. Why is this? There are a lot of questions in the site which boil down to OP not knowing he/she needs to escape backslashes in file paths in the source code. The questions are usually "Why is my program not working?" or "Why is the file not found?", and somewhere in the source code there will be: const char *fileName = "C:\unescaped\backslashes.txt";