character

How to replace all characters in a user input string except one

℡╲_俬逩灬. 提交于 2019-12-19 19:56:38
问题 I'm currently in an introductory level Java class, and am working on the classic phrase guess assignment. The object is for one user to enter a secret phrase, and another to guess it one letter at a time. Between guesses, the phrase must be displayed as all question marks except the letters that were guessed correctly. Our class has only really covered some very basic methods, if-else statements and loops up to this point, but I'm trying to research some string methods that may make this a

Getting two characters from string in python

99封情书 提交于 2019-12-19 17:48:08
问题 how to get in python from string not one character, but two? I have: long_str = 'abcd' for c in long_str: print c and it gives me like a b c d but i need to get ab cd I'm new in python.. is there any way? 回答1: for i, j in zip(long_str[::2], long_str[1::2]): print (i+j) or import operator for s in map(operator.add, long_str[::2], long_str[1::2]): print (s) itertools also provide a generalized implementation of this: def grouper(n, iterable, fillvalue=None): "grouper(3, 'ABCDEFG', 'x') --> ABC

Check first character of each line for a specific value in PowerShell

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 17:47:01
问题 I am reading in a text file that contains a specific format of numbers. I want to figure out if the first character of the line is a 6 or a 4 and store the entire line in an array for use later. So if the line starts with a six add the entire line into sixArray and if the line starts with a 4 add the entire line into fourArray. How can I check the first character and then grab the remaining X characters on that line? Without replacing any of the data? 回答1: Something like this would probably

Prolog - List of CharCodes to a String or Characters

风流意气都作罢 提交于 2019-12-19 17:45:39
问题 I have a list of Character Codes in prolog. I would like to change them into characters. For instance, L = "abc" returns L = [97,98,99] Assuming I start with L = [97,98,99] Is there anyway to convert L back into abc such that, if there exists a method convert(L, X) returns X = abc Thanks. 回答1: Given L="abc", convert(L, X), X = abc I'd say that you want to get atom (see Data types description) from prolog string. I guess you want atom_codes/2 or something like that. It should work like L="abc"

regex to replace words with more than two consecutive characters

只愿长相守 提交于 2019-12-19 12:46:05
问题 How can I detect the presence of more than two consecutive characters in a word and remove that word? I seem to be able to do it like this: # example data mystring <- c(1, 2, 3, "toot", "tooooot") # clunky regex gsub("^[[:alpha:]]$", "", gsub(".*(.)\\1+\\1", "", mystring)) [1] "1" "2" "3" "toot" "" But I'm sure there is a more efficient way. How can I do it with just one gsub ? 回答1: You can use grepl instead. mystring <- c(1, 2, 3, "toot", "tooooot", "good", "apple", "banana") mystring[!grepl

Check a string for consecutive repeated characters [closed]

独自空忆成欢 提交于 2019-12-19 11:58:56
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . It is asked in an interview to write the code in Java to display the string which doesn't have consecutive repeated characters. E.g.: Google, Apple, Amazon; It should display "Amazon" I wrote code to find continues repeating char. Is there any algorithm or efficient way to find it

Data frame changes from numeric to character

人盡茶涼 提交于 2019-12-19 10:28:45
问题 I open my csv file and I control the class of each of my data: mydataP<-read.csv("Energy_protein2.csv", stringsAsFactors=F) apply(mydataP, 2, function(i) class(i)) #[1] "numeric" I add a column and check the class of the data: mydataP[ ,"ID"] <-rep(c("KOH1", "KOH2", "KOH3", "KON1", "KON2", "KON3", "WTH1", "WTH2", "WTH3","WTN1", "WTN2", "WTN3"), each=2) apply(mydataP, 2, function(i) class(i)) Here it changes to a "character" as.numeric(as.factor(mydataP)) #Error in sort.list(y) : 'x' must be

Data frame changes from numeric to character

为君一笑 提交于 2019-12-19 10:27:38
问题 I open my csv file and I control the class of each of my data: mydataP<-read.csv("Energy_protein2.csv", stringsAsFactors=F) apply(mydataP, 2, function(i) class(i)) #[1] "numeric" I add a column and check the class of the data: mydataP[ ,"ID"] <-rep(c("KOH1", "KOH2", "KOH3", "KON1", "KON2", "KON3", "WTH1", "WTH2", "WTH3","WTN1", "WTN2", "WTN3"), each=2) apply(mydataP, 2, function(i) class(i)) Here it changes to a "character" as.numeric(as.factor(mydataP)) #Error in sort.list(y) : 'x' must be

Unbuffered character input for python on a windows machine

时光毁灭记忆、已成空白 提交于 2019-12-19 10:16:55
问题 What I am trying to do I am trying to design a stopwatch with lap timing. When you press "L" then a lap is completed and when you press "S" all laps are completed and the timings are displayed in order. While in C++ I can do this with the function _getch() from conio.h and it would be quite easy. I want to write this program in python as it would be a lot more easier and also the time handling in C++ proved to be hard. Still I did write a program (which was for cube timing) on this link: Cube

php code to validate alphanumeric string

时光毁灭记忆、已成空白 提交于 2019-12-19 06:11:59
问题 I want to validate alphanumeric string in form text box in php. It can contain numbers and special characters like '.' and '-' but the string should not contain only numbers and special characters. Please help with the code. 回答1: Try this // Validate alphanumeric if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9._]+$/', $input)) { // Valid } else { // Invalid } 回答2: Use ctype_alnum like below: if(ctype_alnum($string)){ echo "Yes, It's an alphanumeric string/text"; } else{ echo "No, It's not an