character

What characters have to be escaped to prevent (My)SQL injections?

烈酒焚心 提交于 2019-12-17 06:43:29
问题 I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following characters: \0 \n \r \ ' " \Z Now, I looked into OWASP.org's ESAPI security library and in the Python port it had the following code (http://code.google.com/p/owasp-esapi-python/source/browse/esapi/codecs/mysql.py): """ Encodes a character for MySQL. """ lookup = { 0x00 : "\\0", 0x08 : "\\b", 0x09 : "\\t", 0x0a : "\\n", 0x0d : "\\r", 0x1a : "\\Z", 0x22 : '\\"', 0x25 : "\\%", 0x27 : "

agrep: only return best match(es)

狂风中的少年 提交于 2019-12-17 06:38:19
问题 I'm using the 'agrep' function in R, which returns a vector of matches. I would like a function similar to agrep that only returns the best match, or best matches if there are ties. Currently, I am doing this using the 'sdist()' function from the package 'cba' on each element of the resulting vector, but this seems very redundant. /edit: here is the function I'm currently using. I'd like to speed it up, as it seems redundant to calculate distance twice. library(cba) word <- 'test' words <- c(

What method in the String class returns only the first N characters?

若如初见. 提交于 2019-12-17 04:46:43
问题 I'd like to write an extension method to the String class so that if the input string to is longer than the provided length N , only the first N characters are to be displayed. Here's how it looks like: public static string TruncateLongString(this string str, int maxLength) { if (str.Length <= maxLength) return str; else //return the first maxLength characters } What String.*() method can I use to get only the first N characters of str ? 回答1: public static string TruncateLongString(this

Finding the indexes of multiple/overlapping matching substrings

时光总嘲笑我的痴心妄想 提交于 2019-12-17 03:20:21
问题 I have a string, s="CCCGTGCC" and a subtstring ss="CC" . I want to get all the indexes in s that start the string ss . In my example I would want to get back the array c(1,2,6) . Is there any string function that achieves this? Notice that my string is in the form "CCCGTGCC" , and not c("C","C","C","G","T","G","C","C") . grep only returns whether there is a match anywhere in the string, and not the indexes of the matches within the string, unless I'm missing something. 回答1: Try gregexpr with

'Fill' Unicode characters in labels

谁都会走 提交于 2019-12-17 02:31:37
问题 How to 'fill' Unicode characters in labels in Swing? I'm trying to make a user interface for the chess program I've recently programmed (with chess pieces something like seen above). In it I'm using unicode characters to represent my chess pieces ( \u2654 through \u265F ). The problem is as follows: When I set the background of my chess piece JLabel to something like white, the entire label is filled (in my case it's a 50*50px square of white with the character on top). This leads to my

Indexes of all occurrences of character in a string

无人久伴 提交于 2019-12-17 02:12:11
问题 The following code will print 2 String word = "bannanas"; String guess = "n"; int index; System.out.println( index = word.indexOf(guess) ); I would like to know how to get all the indexes of "n" ("guess") in the string "bannanas" The expected result would be: [2,3,5] 回答1: This should print the list of positions without the -1 at the end that Peter Lawrey's solution has had. int index = word.indexOf(guess); while (index >= 0) { System.out.println(index); index = word.indexOf(guess, index + 1);

Indexes of all occurrences of character in a string

≡放荡痞女 提交于 2019-12-17 02:11:15
问题 The following code will print 2 String word = "bannanas"; String guess = "n"; int index; System.out.println( index = word.indexOf(guess) ); I would like to know how to get all the indexes of "n" ("guess") in the string "bannanas" The expected result would be: [2,3,5] 回答1: This should print the list of positions without the -1 at the end that Peter Lawrey's solution has had. int index = word.indexOf(guess); while (index >= 0) { System.out.println(index); index = word.indexOf(guess, index + 1);

What is the difference between a string and a byte string?

假装没事ソ 提交于 2019-12-16 22:35:09
问题 I am working with a library which returns a byte string and I need to convert this to a string. Although I'm not sure what the difference is - if any. 回答1: Assuming Python 3 (in Python 2, this difference is a little less well-defined) - a string is a sequence of characters, ie unicode codepoints; these are an abstract concept, and can't be directly stored on disk. A byte string is a sequence of, unsurprisingly, bytes - things that can be stored on disk. The mapping between them is an encoding

How can I get the first 10 digits from EditText, and set this digits in a TextView?

筅森魡賤 提交于 2019-12-14 03:59:18
问题 I have a field filled with an EditText control, it figures: 475759403048575663648495004945757590 . What can I use to choose the first 10 numbers from this EditText: and then, insert the numbers 4757594030 , in the TextView? 回答1: You can substring the string to 10 characters. String s = somestring.substring(0,10); So this will return the first 10 characters, and now you can put the value S in your control! 回答2: You can put a textwatcher to the edittext, then count as the edit text is being

Convert time values to numeric while keeping time characteristics

筅森魡賤 提交于 2019-12-14 03:57:41
问题 I have a data set which contains interval times of different events occurring. What I want to do, is convert the data into a numeric vector, so its easier to manipulate and run summaries/make graphs etc, while keeping its time characteristics. Here is a snippet of my data: data <- c( "03:31", "12:17", "16:29", "09:52", "04:01", "09:00", "06:29", "04:17", "04:42") class(data) [1] character The obvious answer is : as.numeric(data) But I get this error: Warning message: NAs introduced by