escaping

PHP: Work with a large string with quotes

百般思念 提交于 2020-01-21 19:43:10
问题 Suppose I have a large string of HTML code. It has both double quotes and single quotes. How can I work with such a string? I want to assign it to a php var but there's a quote clash whether I use double quotes or single quotes. Is there any way to assign this string to a var without having to manually add slashes to all the quotes? It could be something like this: <div class="name">Sally O'Connel</div> Only the string is longer so there will be multiple occurances of single quotes and double

PHP: Work with a large string with quotes

我与影子孤独终老i 提交于 2020-01-21 19:42:27
问题 Suppose I have a large string of HTML code. It has both double quotes and single quotes. How can I work with such a string? I want to assign it to a php var but there's a quote clash whether I use double quotes or single quotes. Is there any way to assign this string to a var without having to manually add slashes to all the quotes? It could be something like this: <div class="name">Sally O'Connel</div> Only the string is longer so there will be multiple occurances of single quotes and double

Java DOM transforming and parsing arbitrary strings with invalid XML characters?

爱⌒轻易说出口 提交于 2020-01-21 11:49:08
问题 First of all I want to mention that this is not a duplicate of How to parse invalid (bad / not well-formed) XML? because I don't have a given invalid (or not well-formed) XML file but rather a given arbitrary Java String which may or may not contain an invalid XML character. I want to create a DOM Document containing a Text node with the given String , then transform it to a file. When the file is parsed to a DOM Document I want to get a String which is equal to the initial given String . I

How to remove escape sequences from stream

≯℡__Kan透↙ 提交于 2020-01-21 08:29:06
问题 is there an quick way to find(and remove) all escape sequences from a Stream/String?? 回答1: Hope bellow syntax will be help full for you string inputString = @"hello world]\ "; StringBuilder sb = new StringBuilder(); string[] parts = inputString.Split(new char[] { ' ', '\n', '\t', '\r', '\f', '\v','\\' }, StringSplitOptions.RemoveEmptyEntries); int size = parts.Length; for (int i = 0; i < size; i++) sb.AppendFormat("{0} ", parts[i]); 回答2: The escape sequences that you are referring to are

How to properly escape quotes in powershell v2?

时间秒杀一切 提交于 2020-01-21 05:52:10
问题 How do you properly escape quotes in powershell v2 (called from within a batch file)? I have tried: powershell -Command "(gc file1.txt) -join "`n" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join ""`n"" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join '"`n`" | Out-File file2.txt" but they all fail. Editor's note : The purpose of the command is to transform Windows CRLF line breaks to Unix LF-only ones, so as to create a file that will be processed on

java resultset.getstring(“col_name”) query

依然范特西╮ 提交于 2020-01-21 05:35:10
问题 I have a simple query regarding ResultSet.getString() method in java for JDBC. Suppose the value in the Database column is having a \ which is javas escape character e.g. \n or \t etc. When i retrieve the value as getString() i see one more escape character is getting added and the actual meaning of this \n is now a string literal only. So i had to unescape java and then use it properly. String s= rs.getString("col_name"); When s contains `\n': System.out.println(s) output: \n After

Replace “&” to “\&” in Ruby seems impossible?

ぃ、小莉子 提交于 2020-01-21 05:17:17
问题 I want to replace all & characters into \& with String.gsub (or a other method). I've tried several combinations and read another question here, but nothing is gonna work. "asdf & asdf".gsub("&", "\\\&") => "asdf & asdf" 回答1: Your linked question provides a solution - use the block form of gsub : irb(main):009:0> puts "asdf & asdf".gsub("&"){'\&'} asdf \& asdf 回答2: I'm going to guess that you're using 1.8. In 1.8, irb says this: >> "asdf & asdf".gsub("&", "\\\&") => "asdf & asdf" >> puts

json.dumps(): escaping forward slashes

让人想犯罪 __ 提交于 2020-01-21 05:00:08
问题 Since forward slashes can only occur in strings inside a JSON serialized object and are not escaped (in the default settings), using json.dump(some_dict).replace('/', r'\/') reliably works, but it looks hacky. I know that forward slashes don't have to be escaped, but you may escape them, and for my usecase I'd like to have them escaped. Is there a way to to let the JSONEncoder escape forward slashes without manually escaping them? 回答1: Only escape forward slashes when encode_html_chars=True

Append HTML-escaped text: jQuery

痞子三分冷 提交于 2020-01-20 05:03:08
问题 I'm used to using jQuery's .append() method to add text or HTML onto the end of a pre-existing element. I'm currently using jQuery's .text() to escape strings that could potentially contain HTML. Unfortunately, there doesn't seem to be a jQuery method that will append the results of the .text() method to an element instead of replacing its contents. Is there a way to append, instead of replace, this escaped text to an element? Or is there a better way to escape strings containing HTML? Thanks

Append HTML-escaped text: jQuery

烂漫一生 提交于 2020-01-20 05:03:07
问题 I'm used to using jQuery's .append() method to add text or HTML onto the end of a pre-existing element. I'm currently using jQuery's .text() to escape strings that could potentially contain HTML. Unfortunately, there doesn't seem to be a jQuery method that will append the results of the .text() method to an element instead of replacing its contents. Is there a way to append, instead of replace, this escaped text to an element? Or is there a better way to escape strings containing HTML? Thanks