backslash

Escape backslash in variable

别说谁变了你拦得住时间么 提交于 2019-12-02 05:24:29
问题 I am using sed to replace url's in a file, everything works fine just a hiccup when the url contains a '\' exmaple url: http* * ://www.example.com/simi/icr # variables ICR_KEY=somekey ICR_KEY_VAL="http\://www.example.com/simi/icr" sed "s!${ICR_KEY}=.*!${ICR_KEY}=${ICR_KEY_VAL}!" properties > tmp This replaces the URL, but the output does not contain the backslash from the variable value. 回答1: Both bash and sed interpret the backslash as escape character. Use single quotes to prevent this for

Escape backslash in variable

大兔子大兔子 提交于 2019-12-02 04:42:54
I am using sed to replace url's in a file, everything works fine just a hiccup when the url contains a '\' exmaple url: http* * ://www.example.com/simi/icr # variables ICR_KEY=somekey ICR_KEY_VAL="http\://www.example.com/simi/icr" sed "s!${ICR_KEY}=.*!${ICR_KEY}=${ICR_KEY_VAL}!" properties > tmp This replaces the URL, but the output does not contain the backslash from the variable value. Both bash and sed interpret the backslash as escape character. Use single quotes to prevent this for bash, and double the backslash for sed: ICR_KEY_VAL='http\\://www.example.com/simi/icr' 来源: https:/

Using a BackSlash in Java [duplicate]

依然范特西╮ 提交于 2019-12-02 04:20:23
This question already has an answer here: What is the backslash character (\\)? 6 answers 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("\"); System.out.println("\\"); \ will escape the second \ character. 来源: https://stackoverflow.com/questions/30781026/using-a-backslash-in-java

Check if string contains single backslashes with regex

[亡魂溺海] 提交于 2019-12-02 03:57:34
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 need to be able to check the strings somehow. It seems you just want to check if a string matches a

Removing backslash from strings in R

时光怂恿深爱的人放手 提交于 2019-12-01 23:49:19
I want to remove list(\" and \") from strings such as list(\"TSPAN6\") and get TSPAN6 . I tried to do that with grep function, however I have problem with backslashes included the strings. I tried: gsub('list(\\"','', "list(\"TSPAN6\")", fixed=T) but it does not work?! I appreciate if you could help me. Using one single gsub . x <- c("list(\"TSPAN6\")") x [1] "list(\"TSPAN6\")" gsub('list|[[:punct:]]', "", x) [1] "TSPAN6" I found it: a <- gsub('list(\"','', "list(\"TSPAN6\")", fixed=T) gsub('\")','', a, fixed=T) [1] "TSPAN6" 来源: https://stackoverflow.com/questions/31728090/removing-backslash

Replacing backslash with another symbol in PHP

余生颓废 提交于 2019-12-01 21:35:42
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 = preg_replace("\", ".-.", $_FILES['uploadfile']['tmp_name']); It turns out into a php error as \ is also

Text replacement with backslash in a variable in Perl

北城余情 提交于 2019-12-01 21:17:38
How can I replace the backslash inside the variable? $string = 'a\cc\ee'; $re = 'a\\cc'; $rep = "Work"; #doesnt work in variable $string =~ s/$re/$rep/og; print $string."\n"; #work with String $string =~ s/a\\cc/$rep/og; print $string."\n"; output: a\cc\ee Work\ee Because you're using this inside of a regex -- you probably want quotemeta() or \Q and \E (see perldoc perlre ) perl -E'say quotemeta( q[a/asf$#@ , d] )' # prints: a\/asf\$\#\@\ \,\ d # Or, with `\Q`, and `\E` $string =~ s/\Q$re\E/$rep/og; print $string."\n"; If you set $re = 'a\cc'; , it would work. The backslash is not getting

NSString Backslash escaping

孤者浪人 提交于 2019-12-01 20:45:41
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 NSString *escapedString = [unescapedString stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];

Getting rid of backslash at the end of wrapped lines (for copy-paste)

别说谁变了你拦得住时间么 提交于 2019-12-01 18:03:12
Emacs in text-mode puts a \ character (backslash) at the end of a wrapped line. I would like to not have that displayed, so I can copy-paste from such a window into another one, without getting the \ in the pasted text. I'm sure there is an easy solution for this, but I couldn't find it (neither online, nor in the emacs manual). The closest seems to be Disable little arrows on far end of line . Distilled from all the replies and links therein, this is what I ended up using for emacs (22.1.1) included in Mac OS X 10.8.3. It works great. Thanks again for all the help! ;; copy to Mac clipboard

Getting rid of backslash at the end of wrapped lines (for copy-paste)

给你一囗甜甜゛ 提交于 2019-12-01 17:37:29
问题 Emacs in text-mode puts a \ character (backslash) at the end of a wrapped line. I would like to not have that displayed, so I can copy-paste from such a window into another one, without getting the \ in the pasted text. I'm sure there is an easy solution for this, but I couldn't find it (neither online, nor in the emacs manual). The closest seems to be Disable little arrows on far end of line. Distilled from all the replies and links therein, this is what I ended up using for emacs (22.1.1)