user-input
How can I use powershell’s read-host function to accept a password for an external service?
$Password is a Securestring, and this will return the plain text password. [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
IO happens out of order when using getLine and putStr
As Michael said, the issue is buffering. By default, output is buffered until you print a newline (or until the buffer is full if you have really long lines), so you’ll most often see this issue when trying to do same-line prompts using putStr like you’re doing. I suggest defining a small helper function like …
How to protect against diacritics such as Zalgo text
is there even a limit?! Not intrinsically in Unicode. There is the concept of a ‘Stream-Safe’ format in UAX-15 that sets a limit of 30 combiners… Unicode strings in general are not guaranteed to be Stream-Safe, but this could certainly be taken as a sign that Unicode don’t intend to standardise new characters that would …
Using isdigit for floats?
EAFP try: x = float(a) except ValueError: print(“You must enter a number”)
Converting String Array to an Integer Array
You could read the entire input line from scanner, then split the line by , then you have a String[], parse each number into int[] with index one to one matching…(assuming valid input and no NumberFormatExceptions) like String line = scanner.nextLine(); String[] numberStrs = line.split(“,”); int[] numbers = new int[numberStrs.length]; for(int i = 0;i < …
How to get user input in Clojure?
read-line is the correct function.. (println (read-line)) ..would basically echo the users input: Clojure 1.0.0- user=> (println (read-line)) this is my input this is my input To use it in an if statement, you’d probably use let: (let [yayinput (read-line)] (if (= yayinput “1234”) (println “Correct”) (println “Wrong”))) Hope that’s enough to get you started, …
In a bash script, how do I sanitize user input?
As dj_segfault points out, the shell can do most of this for you. Looks like you’ll have to fall back on something external for lower-casing the string, though. For this you have many options, like the perl one-liners above, etc., but I think tr is probably the simplest. # first, strip underscores CLEAN=${STRING//_/} # next, …
How to use View.OnTouchListener instead of onClick
The event when user releases his finger is MotionEvent.ACTION_UP. I’m not aware if there are any guidelines which prohibit using View.OnTouchListener instead of onClick(), most probably it depends of situation. Here’s a sample code: imageButton.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_UP){ // Do what you want return true; …
Which is the best way to get input from user in C?
Generally, fgets() is considered a good option. It reads whole lines into a buffer, and from there you can do what you need. If you want behavior like scanf(), you can pass the strings you read along to sscanf(). The main advantage of this, is that if the string fails to convert, it’s easy to …