backslash

Python prints two backslash instead of one [duplicate]

拜拜、爱过 提交于 2020-01-25 11:57:07
问题 This question already has answers here : Difference between __str__ and __repr__? (22 answers) Closed 3 months ago . My goal is to print a backslash in Python3. My input is links22 = ['1',"n","nkf"] treee = ['<img src={} \>'.format(i) for i in links22] print(treee) The output that I get is: ['<img src=1 \\>', '<img src=n \\>', '<img src=nkf \\>'] And when I try: print("\\") The output is: \ I want to figure out why the first output is \ and in the second is . 回答1: The first \ is escaping the

Check if string contains single backslashes with regex

纵饮孤独 提交于 2020-01-22 01:48:27
问题 I have tried to fix this for a long time, and i just can't do it. It could be any string, but this is an example: "\This string \contains some\ backslashes\" I need to make a regex that i can use to check that the string contains single backslashes. I then need to convert the given string into (i can do the conversion): "\\This string \\contains some\\ backslashes\\" And then use regex to check that the string no long contains single backslashes. Btw i dont have to use regex for this, i just

How to replace backslash followed by 't' or any other alphabet or character in escape chacter in file path to forward slash in java?

≯℡__Kan透↙ 提交于 2020-01-16 14:30:44
问题 I'm importing a CSV file to MySQL database. This can be done using java.mysql support for forward slash in file path. If user gives the path String filepath=" c:\upload\date\csv\sample.csv"; we can do it by replacing '\' with '/' using following line of code. String filepath2=filepath.replace("\\","/"); but when user enters path as follows String filepath=" c:\test.csv"; the replace function unable to replace "\\" with "/" as '\' in the filepath does not remain '\' as '\' is followed by 't'

How to replace backslash followed by 't' or any other alphabet or character in escape chacter in file path to forward slash in java?

我们两清 提交于 2020-01-16 14:30:33
问题 I'm importing a CSV file to MySQL database. This can be done using java.mysql support for forward slash in file path. If user gives the path String filepath=" c:\upload\date\csv\sample.csv"; we can do it by replacing '\' with '/' using following line of code. String filepath2=filepath.replace("\\","/"); but when user enters path as follows String filepath=" c:\test.csv"; the replace function unable to replace "\\" with "/" as '\' in the filepath does not remain '\' as '\' is followed by 't'

Searching for backslash in a string with Powershell

吃可爱长大的小学妹 提交于 2020-01-16 00:49:20
问题 I need to search for the amount of backslashes in a string to determine some file path parameters. I have not worked out a way to seach for a backslash without Powershell thinking it is an escapee character. ([regex]::Matches($FilePath, "\" )).count Or $a -match "\" These both come up with an error "Illegal \ at end of pattern" Thanks! 回答1: You can escape a backslash with a backslash: [Regex]::Matches($FilePath, "\\").Count 来源: https://stackoverflow.com/questions/35497077/searching-for

Problem Replacing Literal String \r\n With Line Break in PHP

◇◆丶佛笑我妖孽 提交于 2020-01-15 08:01:08
问题 I have a text file that has the literal string \r\n in it. I want to replace this with an actual line break (\n). I know that the regex /\\r\\n/ should match it (I have tested it in Reggy), but I cannot get it to work in PHP. I have tried the following variations: preg_replace("/\\\\r\\\\n/", "\n", $line); preg_replace("/\\\\[r]\\\\[n]/", "\n", $line); preg_replace("/[\\\\][r][\\\\][n]/", "\n", $line); preg_replace("/[\\\\]r[\\\\]n/", "\n", $line); If I just try to replace the backslash, it

Check if string containts slash or backslash in Bash?

只愿长相守 提交于 2020-01-13 12:12:28
问题 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 回答1: 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 $ $

Using a BackSlash in Java [duplicate]

為{幸葍}努か 提交于 2020-01-11 12:53:09
问题 This question already has answers here : What is the backslash character (\\)? (6 answers) Closed 4 years ago . I want to print out a backslash. However, I get an error: //Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) System.out.println("\"); 回答1: System.out.println("\\"); \ will escape the second \ character. 来源: https://stackoverflow.com/questions/30781026/using-a-backslash-in-java

Replacing backslash with another symbol in PHP

倖福魔咒の 提交于 2020-01-11 09:51:34
问题 Been struggling with replacing a backslash by another symbol such as '.-.' just to indicate the position of backslashes as I could not send a string such as 'C\xampp\etc.' through url as GET variable so I thought I'd first replace the backslashes in that string by another symbol, then send through url, and then replace them back to backslashes in the PHP file that handles it. Though would there be a better way to send such strings through url? Because when I try a script such as: $tmp_name =

TCL: Backslash issue (regsub)

家住魔仙堡 提交于 2020-01-04 05:43:10
问题 I have an issue while trying to read a member of a list like \\server\directory The issue comes when I try to get this variable using the lindex command, that proceeds with TCL substitution, so the result is: \serverdirectory Then, I think I need to use a regsub command to avoid the backslash substitution, but I did not get the correct proceedure. An example of what I want should be: set mistring "\\server\directory" regsub [appropriate regular expresion here] puts "mistring: '$mistring'" ==>