numbers

Regex to match a digit two or four times

夙愿已清 提交于 2019-12-18 10:31:58
问题 It's a simple question about regular expressions, but I'm not finding the answer. I want to determine whether a number appears in sequence exactly two or four times. What syntax can I use? \d{what goes here?} I tried \d{2,4} , but this expression accepts three digits as well. 回答1: There's no specific syntax for that, but there are lots of ways to do it: (?:\d{4}|\d{2}) <-- alternation: four digits or two \d{2}(?:\d{2})? <-- two digits, and optionally two more (?:\d{2}){1,2} <-- two digits,

Generating a sequence using prime numbers 2, 3, and 5 only, and then displaying an nth term (C++)

时间秒杀一切 提交于 2019-12-18 09:49:07
问题 I'm working on a problem that asks to generate a sequence using prime numbers 2, 3, and 5, and then displaying then nth number in the sequence. So, if I ask the program to display the 1000th number, it should display it. I can't be using arrays or anything like that, just basic decisions and loops. I started working on it and hit a wall... here's what I got: #include <iostream> using namespace std; int main() { unsigned int n=23; for(int i=2; i<n; i++){ if(i%2==0){ cout<<i<<", "; }else if(i%3

Print largest number in a 2d array - why do my code print three numbers

旧巷老猫 提交于 2019-12-18 09:23:35
问题 I am trying to print out the largest number in a 2D array. My problem is that my output are three numbers instead of one - the largest. Why? Here is my code: public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int maxRows = 3; int maxCols = 4; int [] onedArray = new int [maxRows]; for (int i = 0; i < maxRows; i++){ onedArray[i] = (int) ((Math.random() * 100) * maxCols); } int [][] twodArray = new int[maxRows][]; for (int i = 0; i <

extracting a number from a string in Java

ぃ、小莉子 提交于 2019-12-18 08:56:12
问题 I have a string with a number inside and I want to retrieve that number. for example if I have a string "bla bla 45 bla bla" I want to get the number 45. I have searched a bit and found out that this code should make the work Matcher matcher = Pattern.compile("\\d+").matcher("bla bla 45 bla bla"); if(matcher.matches()) String result = matcher.group(); but it doesn't :( probably the problem is that "\d+" regular expression is converted to "^\d+$" and so the matcher doesn't matches the number

extracting a number from a string in Java

六眼飞鱼酱① 提交于 2019-12-18 08:56:09
问题 I have a string with a number inside and I want to retrieve that number. for example if I have a string "bla bla 45 bla bla" I want to get the number 45. I have searched a bit and found out that this code should make the work Matcher matcher = Pattern.compile("\\d+").matcher("bla bla 45 bla bla"); if(matcher.matches()) String result = matcher.group(); but it doesn't :( probably the problem is that "\d+" regular expression is converted to "^\d+$" and so the matcher doesn't matches the number

R: removing numbers at begin and end of a string

孤街浪徒 提交于 2019-12-18 08:48:12
问题 I've got the following vector: words <- c("5lang","kasverschil2","b2b") I want to remove "5" in "5lang" and "2" in "kasverschil2" . But I do NOT want to remove "2" in "b2b" . 回答1: gsub("^\\d+|\\d+$", "", words) #[1] "lang" "kasverschil" "b2b" Another option would be to use stringi library(stringi) stri_replace_all_regex(words, "^\\d+|\\d+$", "") #[1] "lang" "kasverschil" "b2b" Using a variant of the data set provided by the OP here are benchmarks for 3 three main solutions (note that these

PHP json_decode integers and floats to string

泪湿孤枕 提交于 2019-12-18 08:19:08
问题 I want to pre-parse a json an convert all numbers in the json (integers or float) to strings. For example: { "integer": 10000, "big_integer": 100000999499498485845848584584584, "float1" : 1.121212, "float2" : 8.226347662837406e+09 } to this: { "integer": "10000", "big_integer": "100000999499498485845848584584584", "float1" : "1.121212", "float2" : "8226347662.837406" } Update I have found the following but it does not work for floats: $jsonString = '[{"name":"john","id":5932725006},{"name":

How can I view Arabic/Persian numbers in a HTML page with strict doctype?

房东的猫 提交于 2019-12-18 07:34:47
问题 I have an HTML page that is right-to-left. When I don't use any doctype, my numbers are in Arabic/Persian, but when I use strict mode they turn to English. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN"> Before adding doctype: After adding doctype: also I added these meta tags to my page: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Language" content="fa" /> So how can I view Arabic numbers in a page with strict doctype (in IE because

Parse multiple doubles from a String

只愿长相守 提交于 2019-12-18 07:05:05
问题 I would like to know how to parse several double numbers from a string, but string can be mixed, for instance: String s = "text 3.454 sometext5.567568more_text" . The standard method ( Double.parseDouble ) is unsuitable. I've tried to parse it using the isDigit method, but how to parse other characters and . ? thanks. 回答1: After parsing your doubles with the suitable regular expressions like in this code or in other posts, iterate to add the matching ones to a list. Here you have myDoubles

What models of Samsung smartphones have missing period for html5 input type=“number”?

此生再无相见时 提交于 2019-12-18 06:18:21
问题 HTML5 has a new input type named "number". On most mobile smartphones this brings up a numeric keypad. On pre-html5 phones the type falls back to "text" and we are OK. Yet, on some models the numeric keypad does not have a period and one cannot click the "symbols" button to add one. Known models with this flaw are: Samsung Galaxy S4, see: Missing period for Samsung Galaxy S4 numeric keypad Samsung Galaxy Note II Samsung Galaxy Tab 2 10". see: Samsung Galaxy Tablet does not allow entering