user-input

How can I limit the number of characters for a console input? C#

非 Y 不嫁゛ 提交于 2019-12-18 09:47:14
问题 Basically I want 200 characters maximum to come up in Console.ReadLine() for user input before characters start being suppressed. I want it like TextBox.MaxLength except for console input. How would I go about this? And I don't want to do input.Substring(0, 200). Solved: I used my own ReadLine function which was a loop of Console.ReadKey(). It looks like this, essentially: StringBuilder sb = new StringBuilder(); bool loop = true; while (loop) { ConsoleKeyInfo keyInfo = Console.ReadKey(true);

Input handling in WinForm

做~自己de王妃 提交于 2019-12-18 09:00:45
问题 What is the best way to block certain input keys from being used in a TextBox with out blocking special keystrokes such as Ctrl-V/Ctrl-C? For example, only allowing the user to enter a subset of characters or numerics such as A or B or C and nothing else. 回答1: I would use the keydown-event and use the e.cancel to stop the key if the key is not allowed. If I want to do it on multiple places then I would make a user control that inherits a textbox and then add a property AllowedChars or

How to create a function for recursively generating iterating functions

假装没事ソ 提交于 2019-12-18 04:55:15
问题 I currently have a bit of Python code that looks like this: for set_k in data: for tup_j in set_k: for tup_l in tup_j: The problem is, I'd like the number of nested for statements to differ based on user input. If I wanted to create a function which generated n number of for statements like those above, how might I go about doing that? 回答1: def nfor(data, n=1): if n == 1: yield from iter(data) else: for element in data: yield from nfor(element, n=n-1) Demo: >>> for i in nfor(['ab', 'c'], n=1)

How to preform whitelist-based CSS filtering in PHP

风格不统一 提交于 2019-12-18 04:48:09
问题 I am working on a site and I would like to make a user able to enter custom CSS into that will be publicly displayed. However, seeing as a good deal of XSS attacks can be preformed through CSS, I would like to be able to find a way to "clean" the CSS output, similar to how HTML Purifier works, by parsing the CSS, running the parsed CSS against a whitelist, and then outputting a new stylesheet based on the parsed and whitelisted CSS. Is there already a library like this out there? If not, is

PHP - HTML Purifier - hello w<o>rld/world tutorial striptags

丶灬走出姿态 提交于 2019-12-17 22:52:07
问题 I am just looking into using HTML Purifier to ensure that a user-inputed string (that represents the name of a person) is sanitized. I do not want to allow any html tags, script, markup etc - I just want the alpha, numeric and normal punctuation characters. The sheer number of options available for HTML Purifier is daunting and, as far as i can see, the docs do not seem to have a beggining/middle or end see: http://htmlpurifier.org/docs Is there a simple hello world tutorial online for HTML

User input to repeat program in Java

岁酱吖の 提交于 2019-12-17 21:14:31
问题 I am writing a simple guessing game program where the user will input a number to try and guess a randomly generated number. If they get the number right I want to give them the option to play again. Here is my code: public class GuessingGame { private Random num = new Random(); private int answer = num.nextInt(10); private int guess; private String playAgain; public void inputGuess(){ System.out.println("Enter a number between 1 and 10 as your first guess: "); Scanner input = new Scanner

Inner HTML with input values

落爺英雄遲暮 提交于 2019-12-17 19:36:55
问题 have a brief question regarding innerHTML and input values that have been entered. See the brief example below (using jQuery for convenience): http://jsfiddle.net/F7urT/2/ jQuery: jQuery(document).ready(function($) { $('.send').click(function() { alert( $('.content').html() ); return false; }); });​ html: <div class="content"> <input type="text" name="input" value="Old Value" /> <input type="button" class="send" value="Send" /> </div>​ If you edit the input value, then click the 'Send' button

How to use int16_t or int32_t with functions like scanf [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-17 19:32:54
问题 This question already has answers here : printf format specifiers for uint32_t and size_t (4 answers) Closed 5 years ago . The way that I understand int16_t or int32_t in C is that they are typedefed to be 16 and 32 bit numbers respectively on your computer. I believe you would use these when you need to guarentee a number is 16 or 32 bits because different systems do not always represent an int as 32 bits or a short as 16 bits (Is this assumption correct? I find mixed answers when I look

Allow only selected charcters based on regex in an EditText

断了今生、忘了曾经 提交于 2019-12-17 19:04:03
问题 I want to allow users only to type certain characters based on the a regex in my android applications. How do I achieve it? 回答1: Used a TextWatcher as @Matt Ball suggested. @Override public void afterTextChanged(Editable s) { String text = s.toString(); int length = text.length(); if(length > 0 && !Pattern.matches(PATTERN, text)) { s.delete(length - 1, length); } } Edit Although the TextWatcher works, it would be cleaner to use an InputFilter . Check this example. 回答2: Try this: If the

Allow only selected charcters based on regex in an EditText

萝らか妹 提交于 2019-12-17 19:02:09
问题 I want to allow users only to type certain characters based on the a regex in my android applications. How do I achieve it? 回答1: Used a TextWatcher as @Matt Ball suggested. @Override public void afterTextChanged(Editable s) { String text = s.toString(); int length = text.length(); if(length > 0 && !Pattern.matches(PATTERN, text)) { s.delete(length - 1, length); } } Edit Although the TextWatcher works, it would be cleaner to use an InputFilter . Check this example. 回答2: Try this: If the