escaping

need to escape # (hash/pound) character in .htaccess rewrite rule

Deadly 提交于 2019-11-29 09:18:40
The question is fairly simple but I was not able to find an answer for hours now. What I need to do is: RewriteRule ([^#])#(.*) $1\%23$2 Which basically means I want to url escape the freaking hash sign which comes to me from an external codepiece. backslash ( \ ) does not work to escape this sign... and please don't suggest using %23 instead # because it does not work as well. ( %2 3 does not match a # because it simply is not == %23 ) The hash part of a URL is not available for rewriting. When a web browser sends a URL request to a web server it sends everything up to the hash sign. The hash

Do I need to escape backslash in a config file?

久未见 提交于 2019-11-29 09:04:41
I have a config file, myapp.exe.config. In the file I have an attribute with a fullpath filename as the value. <add key="InfoFile" value="c:\temp\info.txt" /> It seems to work if I use a single or double backslash. That is, <add key="InfoFile" value="c:\\temp\\info.txt" /> works also. What is the correct way to do this? You don't need that. Anything within an attribute value is character data. Since you're reading these values using C#, they'll get escaped as if they would be a literal path string in code. Anyway, you might want to know that C# has @ operator to declare verbatim strings,

Replace \\\\ with \\ in C#

偶尔善良 提交于 2019-11-29 08:50:37
I have a long string (a path) with double backslashes, and I want to replace it with single backslashes: string a = "a\\b\\c\\d"; string b = a.Replace(@"\\", @"\"); This code does nothing... b remains "a\\b\\c\\d" I also tried different combinations of backslashes instead of using @ , but no luck. In C#, you can't have a string like "a\b\c\d" , because the \ has a special meaning: it creates a escape sequence together with a following letter (or combination of digits). \b represents actually a backspace, and \c and \d are invalid escape sequences (the compiler will complain about an

MySQL unicode literals

杀马特。学长 韩版系。学妹 提交于 2019-11-29 08:04:41
问题 I want to insert a record into MySQL that has a non-ASCII Unicode character, but I'm on a terminal that doesn't let me easily type non-ASCII characters. How do I escape a Unicode literal in MySQL's SQL syntax? 回答1: See: http://bugs.mysql.com/bug.php?id=10199 (Bug #10199: "Allow Unicode escape sequence for string literals.") This request has been "Open" since 2005. More details in Worklog Task #3529: Unicode Escape Sequences. From https://web.archive.org/web/20091117221116/http://eng.kaching

How to read until ESC button is pressed from cin in C++

和自甴很熟 提交于 2019-11-29 08:03:06
I'm coding a program that reads data directly from user input and was wondering how could I read all data until ESC button on keyboard is pressed. I found only something like this: std::string line; while (std::getline(std::cin, line)) { std::cout << line << std::endl; } but need to add a portable way (Linux/Windows) to catch a ESC button pressed and then break a while loop. How to do this? EDIT: I wrote this, but still - works even if I press an ESC button on my keyboard: #include <iostream> #include <string> using namespace std; int main() { const int ESC=27; std::string line; bool moveOn =

passing quoted arguments from batch file to `powershell start` - self-elevation on demand

假装没事ソ 提交于 2019-11-29 08:02:52
I am writing a Windows batch file that automatically escalates itself to administrative permissions, provided the user clicks "Yes" on the User Access Control dialog that appears. I am using a technique I learned here to detect whether we already have admin rights and another from here to escalate. When appropriate, the following script, let's call it foo.bat , re-launches itself via a powershell-mediated call to runas : @echo off net session >NUL 2>NUL if %ERRORLEVEL% NEQ 0 ( powershell start -wait -verb runas "%~dpfx0" -ArgumentList '%*' goto :eof ) echo Now we are running with admin rights

How to use Json.NET StringEscapeHandling.EscapeNonAscii [duplicate]

北城以北 提交于 2019-11-29 07:48:26
Possible Duplicate: Using StringEscapeHandling.EscapeNonAscii with Json.NET The latest release of Json.NET (4.5.11) contains StringEscapeHandling.EscapeNonAscii , which escapes all non ASCII chars. But, I can't figure out how to use it. The docs don't seem to have any examples that I can find (only a release note announcing it). Could someone show an example of serializing an object into a JSON string, using EscapeNonAscii ? Maybe this example can help string obj = "abcn\n\rüö&/<>"; Console.WriteLine(Serialize(obj, StringEscapeHandling.Default)); Console.WriteLine(Serialize(obj,

Rails 4, link in flash message is not parsed as HTML

偶尔善良 提交于 2019-11-29 07:43:12
In controller I have the following flash message: flash[:notice] = %Q[Please #{view_context.link_to('create a new account', new_account_path)}, after that you will be able to create orders.].html_safe Here is flash area in layout: <div id="main_flash_area"> <% flash.each do |name, msg| %> <div class="alert text-center alert-info"> <a class="close" data-dismiss="alert">× Закрыть</a> <%= msg %> </div> <% end %> </div> It kinda renders into a link, but browser doesn't parse it as a link though. It is displayed as Please <a href="/accounts/new">create a new account</a>, after that you will be able

PHP equivalent for javascript escape/unescape

痞子三分冷 提交于 2019-11-29 07:41:31
Let's say I have a string: something When I escape it in JS I get this: %73%6F%6D%65%74%68%69%6E%67 so I can use this code in JS to decode it: document.write(unescape('%73%6F%6D%65%74%68%69%6E%67')); I need the escape function in PHP which will do the same (will encode something to : %73%6F%6D%65%74%68%69%6E%67 ) How to do that ? PHP: rawurlencode("your funky string"); JS: decodeURIComponent('your%20funky%20string'); Don't use escape as it is being deprecated. rawurldecode('%73%6F%6D%65%74%68%69%6E%67'); Some clarification first: Let's say I have a string: something When I escape it in JS I

DocumentBuilder parsing breaks string when hits '&'

梦想与她 提交于 2019-11-29 07:41:15
i have this xml: <user> <name>H & M</name> and i parse it using this code: DocumentBuilder documentBuilder = null; Document document = null; try { documentBuilder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); document = documentBuilder.parse(is); } catch (Exception e) { return result; } NodeList nl = document.getElementsByTagName(XML_RESPONSE_ROOT); if (nl.getLength() > 0) { resp_code = nl.item(0).getAttributes().getNamedItem( XML_RESPONSE_STATUS).getNodeValue(); if (resp_code.equals(RESP_CODE_OK_SINGLE)) { nl = document .getElementsByTagName(XML_RESPONSE_TAG_CONTACT); NodeList