backslash

Add backslash to string

こ雲淡風輕ζ 提交于 2019-11-29 06:00:39
I have a path and I want to add to it some new sub folder named test. Please help me find out how to do that. My code is : string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); Console.WriteLine(path+"\test"); The result I'm getting is : "c:\Users\My Name\Pictures est" Please help me find out the right way. Do not try to build pathnames concatenating strings. Use the Path.Combine method string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); Console.WriteLine(Path.Combine(path, "test")); The Path class contains many useful static methods to

How to remove backslash on json_encode() function?

微笑、不失礼 提交于 2019-11-29 03:07:16
How to remove the (\) backslash on a string? when using echo json_encode() ? For example: <?php $str = "$(\"#output\").append(\"<p>This is a test!</p>\")"; echo json_encode($str); ?> note: When you echo $str, there will be no problem... but when you echo out using json_encode() , the (\) backslash will show up. Is there a way to solve this? json_encode($response, JSON_UNESCAPED_SLASHES); Since PHP 5.4 there are constants which can be used by json_encode() to format the json reponse how you want. To remove backslashes use: JSON_UNESCAPED_SLASHES . Like so: json_encode($response, JSON_UNESCAPED

Escape double and single backslashes in a string in Ruby

懵懂的女人 提交于 2019-11-29 02:57:12
问题 I'm trying to access a network path in my ruby script on a windows platform in a format like this. \\servername\some windows share\folder 1\folder2\ Now If I try to use this as a path, it won't work. Single backslashes are not properly escaped for this script. path = "\\servername\some windows share\folder 1\folder2\" d = Dir.new(path) I tried everything I could think of to properly escape slashes in the path. However I can't escape that single backslash - because of it's special meaning. I

How do I add slashes to a string in Javascript?

大城市里の小女人 提交于 2019-11-29 01:32:01
问题 Just a string. Add \' to it every time there is a single quote. 回答1: replace works for the first quote, so you need a tiny regular expression: str = str.replace(/'/g, "\\'"); 回答2: Following JavaScript function handles ', ", \b, \t, \n, \f or \r equivalent of php function addslashes(). function addslashes(string) { return string.replace(/\\/g, '\\\\'). replace(/\u0008/g, '\\b'). replace(/\t/g, '\\t'). replace(/\n/g, '\\n'). replace(/\f/g, '\\f'). replace(/\r/g, '\\r'). replace(/'/g, '\\\'').

Javascript: Replace backslashes with double backslashes

本秂侑毒 提交于 2019-11-28 14:27:37
I'm currently having the problem mentioned in the title and I'm somehow not finding a way to properly replace backsashes with double backslashes, so that I can properly give the string to a webservice as parameters. Let me show you what I tried. Some of these do actually work for some other people, but not for me... I'm currently testing this with FF18.0.1 WSParameters.replace(/\\/g, "\\\\\\\\"); WSParameters.replace("\\", "\\\\\\\\"); WSParameters.replace(/\\/g, "\\\\"); WSParameters.replace(/\\/g, "\\"); WSParameters.replace(/\\/g, "\"); WSParameters.replace("\\", "\\\\"); Thanks a lot in

Error with double backslash in Windows path in Python

ε祈祈猫儿з 提交于 2019-11-28 12:42:08
I want to work with paths in Windows in Python 3.3, but I have an error: FileNotFoundError: [Errno 2] No such file or directory: 'E:\\dir\\.project' The problem is the double backslash. I read the solution using r. def f(dir_from): list_of_directory = os.listdir(dir_from) for element in list_of_directory: if os.path.isfile(os.path.join(dir_from, element)): open(os.path.join(dir_from, element)) f(r'E:\\dir') I have this error again FileNotFoundError: [Errno 2] No such file or directory: 'E:\\dir\\.project' os.path.normpath(path) doesn't solve my problem. What am I doing wrong? iCodez If you are

CMake: how to get the backslash literal in Regexp replace?

一世执手 提交于 2019-11-28 11:01:23
I am trying to replace forwardslashes with backslashes. To do that i have the following line of code: STRING(REGEX REPLACE "/" "\\" SourceGroup ${SourceGroupPath} ) SourceGroupPath = A/File/Path. SourceGroup is the variable to set the result to. The problem i am having is with, the "\\" part to the code. I have tried several ways to getting to use the backslash literal like "\\" and using unicode but nothing seems to work. The error i get in CMake is: CMake Error at CMakeLists.txt:41 (STRING): string sub-command REGEX, mode REPLACE: replace-expression ends in a backslash. Can someone please

Python: '#' Comments after backslash

≡放荡痞女 提交于 2019-11-28 10:39:40
This doesn't work: something = \ line_of_code * \ # Comment another_line_of_code * \ # Comment and_another_one * \ # Comment etc Neither does this: something = \ # Comment \ line_of_code * \ # Comment \ another_line_of_code * ... Neither does this: something = \ ''' Comment ''' \ line_of_code * \ ''' Comment ''' \ another_line_of_code * ... If there a way to make comments in the code broken into multiple lines? Do it like that: a, b, c, d = range(1, 5) result = ( # First is 1 a * # Then goes 2, result is 2 now b * # And then 3, result is 6 c * # And 4, result should be 24 d ) Actually,

Include header path change from Windows to Linux

本秂侑毒 提交于 2019-11-28 10:09:34
I'm porting an application written in C++ from Windows to Linux. I have a problem with the header files path. Windows uses \ and Linux uses / . I am finding it cumbersome to change this in each and every source and header file. Is there some work around? Brian Neal Always use forward slashes in #include paths. It is the compiler's job to map the path to whatever slash/directory scheme the underlying OS supports. You people! Yes , you can, and should, always use forward slashes. I think the issue is how to get there from here ! If you have Perl installed, the following one liner will convert a

Why is '\\x' invalid in Python?

余生长醉 提交于 2019-11-28 08:09:21
I was experimenting with '\' characters, using '\a\b\c...' just to enumerate for myself which characters Python interprets as control characters, and to what. Here's what I found: \a - BELL \b - BACKSPACE \f - FORMFEED \n - LINEFEED \r - RETURN \t - TAB \v - VERTICAL TAB Most of the other characters I tried, '\g', '\s', etc. just evaluate to the 2-character string of a backslash and the given character. I understand this is intentional, and makes sense to me. But '\x' is a problem. When my script reaches this source line: val = "\x" I get: ValueError: invalid \x escape What is so special about