escape

C# alternative for javascript escape function

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: what is an alternative for javascript escape function in c# for e.g suppose a string:"Hi Foster's i'm missing /you" will give "Hi%20Foster%27s%20i%27m%20missing%20/you" if we use javascript escape function, but what is the alternative for c#. i have searched for it but no use. 回答1: You can use: string encoded = HttpUtility . JavaScriptStringEncode ( str ); Note: You need at least ASP.NET 4.0 to run the above code. 回答2: The best solution I've seen is mentioned on this blog - C#: Equivalent of JavaScript escape function by Kaushik

How to escape backslashes in R string

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing strings to a file using R: > x1="\\str" > x2="\\\str" Error: '\s' is an unrecognized escape in character string starting "\\\s" > x2="\\\\str" > write(file='test',c(x1,x2)) When I open the file named test , I see this: \str \\str If I want to get a string containing 5 backslashes, should I write 10 backslashes, like this? x="\\\\\\\\\\str" 回答1: [...] If I want to get a string containing 5 \ ,should i write 10 \ [...] Yes, you should. To write a single \ in a string, you write it as "\\" . This is because the \ is a special

How do I print escape characters in Java

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I have a string such as: String x = "hello\nworld"; How do I get Java to print the actual escape character (and not interpret it as an escape character) when using System.out? For example, when calling System.out.print(x); I would like to see: hello\nworld And not: hello world EDIT: My apologies, I should clarify the question. I have no control over what 'x' is going to be, it may be a string I read from a file. I would like for x to retain its escape characters during normal program execution, but for debugging purposes I would like to

Best way to escape and unescape strings in Ruby?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does Ruby have any built-in method for escaping and unescaping strings? In the past, I've used regular expressions; however, it occurs to me that Ruby probably does such conversions internally all the time. Perhaps this functionality is exposed somewhere. So far I've come up with these functions. They work, but they seem a bit hacky: def escape(s) s.inspect[1..-2] end def unescape(s) eval %Q{"#{s}"} end Is there a better way? 回答1: If you don't want to use eval , but are willing to use the YAML module, you can use it instead: require 'yaml'

Escaping a forward slash in a regular expression

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My question is a simple one, and it is about regular expression escaping. Do you have to escape a forward slash / in a regular expression? And how would you go about doing it? 回答1: What context/language? Some languages use / as the pattern delimiter, so yes, you need to escape it, depending on which language/context. You escape it by putting a backward slash in front of it: \/ For some languages (like PHP) you can use other characters as the delimiter and therefore you don't need to escape it. But AFAIK in all languages, the only special

Python 2.6: “Couldn't open image” error

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to make the base for a map that I'm going to be using for a game, but I can't load the image onto the screen. I've tried sending in an absolute filepath to the image with likesame letter case, I've tried changing the name of the image, I've tried loading different images that worked in other programs I made, and I've tried putting the image in the same directory as the script itself. Nothing has worked yet. I looked at a few threads of people who were having the same problem, such as Why are my pygame images not loading? and I can

Jade - convert new lines to <br/> and keep the content encoded

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am still not that familiar with the Jade template engine. Is there a way to convert the new lines such as \n to br tags and at the same time keep the other content encoded? For example .replace(/\n/g,'') applied over the encoded value should do the work. However I am not sure how to encode the value and get the result. Is there any helper for this? 回答1: You can use jades escape method and replace the linebreaks in the return value of that like so: p !{escape(foo).replace(/\n/g, ' ')} I am not aware of any built-in functionality for your

Filtering out ANSI escape sequences

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a python script that's trying to interpret a trace of data written to and read from stdout and stdin, respectively. The problem is that this data is riddled with ANSI escapes I don't care about. These escapes are JSON encoded, so they look like "\033[A" and "\033]0;". I don't actually need to interpret the codes, but I do need to know how many characters are included in each (you'll notice the first sequence is 6 characters while the second is 7). Is there a straightforward way to filter out these codes from the strings I

Escaping variables

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've read that it's enough and even recommended to escape characters on the output, not on the input. It could be easily applied to all get variables as they are not injected to the database from the form level. However, I'm not sure what to do with all post variables. If it doesn't come from the database, so if it's a raw input data, escaping is fully needed. But I'm using PDO prepare/execute to escape all variables. Questions now: Is it OK to use PDO's prepare/execute both in select and insert statements? Isn't it escaping variables twice

What values can I put in an HTML attribute value?

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Do I need to escape quotes inside of an html attribute value? What characters are allowed? Is this valid? Hi 回答1: If your attribute value is quoted (starts and ends with double quotes " ), then any characters except for double quotes and ampersands are allowed, which must be quoted as " and & respectively (or the equivalent numeric entity references, " and & ) You can also use single quotes around an attribute value. If you do this, you may use literal double quotes within the attribute: ... . In order to escape single quotes within such an