integer

How to grab seperated integers from long string

我是研究僧i 提交于 2019-12-18 09:49:19
问题 I am working on a enrollment system for a judo club. I am using a string to store the ID's of people, who showed up. It looks somthing like this: 0,3,4,7,8,10, Now, I want to seperate each number into an integer array in PHP. What would the simplest solution to this be? :) 回答1: Use explode() $ids = explode(',', '0,3,4,7,8,10'); 回答2: $str = '0,3,4,7,8,10'; $arr = explode(',',$str); 回答3: use EXPLODE $num = "0,3,4,7,8,10"; $pieces = explode(",", $num ); Explode Manual 来源: https://stackoverflow

Inserting integer into array in swift

江枫思渺然 提交于 2019-12-18 09:43:18
问题 I'm not really on point with Swift yet and there is a problem that is starting to be a tad annoying. I just want to add integer in a double dimensional array but it is always returning the same error code : "fatal error : Array index out of range" var arrayVolley = [[Int]]() init(){ self.arrayVolley = [[]] } Here is where I try to insert : func addPoints(score : Int, x : Int, y : Int){ if (score > 11 || score < 0){ //11 will be translated as 10x println("Error on score value") } else { if (x

Convert NSDate to an Integer

送分小仙女□ 提交于 2019-12-18 09:23:47
问题 So my dilemma is that I can't figure out how to store the date only in an integer value (fetched using: NSDate* date = [NSDate date] I found this code online which seems similar to what I need (I thought that changing setDateFormat to @"dd" would've worked (but apparently it didn't) NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy"]; //Optionally for time zone conversions [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]]; NSString

Java Integer parseInt error

ぐ巨炮叔叔 提交于 2019-12-18 09:06:04
问题 I have following problem: I want to convert some Binary Strings to an integer: eargb = Integer.parseInt(al + re + gre + blu, 2); but I get following exception. Why? java.lang.NumberFormatException: For input string: "11111111111000101000100111111010" 回答1: Your number (4,293,036,538) is too large to fit in a signed int (which has a range of -2,147,483,648 to 2,147,483,647). Try using a long instead. This has a larger range. 回答2: How about long eargb = Long.parseLong(al + re + gre + blu, 2);

Haskell Error: Couldn't match expected type `Integer' against inferred type `Int'

a 夏天 提交于 2019-12-18 08:29:27
问题 I have a haskell function that that calculates the size of the list of finite Ints. I need the output type to be an Integer because the value will actually be larger than the maximum bound of Int (the result will be -1 to be exact if the output type is an Int) size :: a -> Integer size a = (maxBound::Int) - (minBound::Int) I understand the difference between Ints (bounded) and Integers (unbounded) but I'd like to make an Integer from an Int. I was wondering if there was a function like

Reading a list of integer in a single input line in C++

[亡魂溺海] 提交于 2019-12-18 07:03:17
问题 I'm trying to read multiple integers from a single input line into an array eg. Input: 100 200 300 400, so the array is: a[0] = 100, a[1] = 200, a[2] = 300, a[3] = 400 The thing is, the number of integers are unknown, so the size of the array is unknown. 回答1: You should use a container that automatically resizes itself, such as std::vector . For example, something like this: #include <string> #include <iostream> #include <sstream> #include <utility> #include <iterator> std::string line;

C#: Array of references / pointers to a number of integers

与世无争的帅哥 提交于 2019-12-18 06:57:37
问题 I would like to hold references to a number of shorts in an array. I assumed I could just create the shorts and then add them to the array. So... every time the referenced object is changed, this is reflected in the array, and vice versa. Doing some trials convinced me that it does not quite work that way. In fact, it looks like the value is transferred but not a reference. Below code creates two shorts, adds these to an array as objects, then changes the original short. However, when

How does Float round when converting it into integer

北战南征 提交于 2019-12-18 06:53:26
问题 If I have (float)value = 10.50 and do int new_value = (int)value what rules will round number? 回答1: When a finite value of floating type is converted to an integer type, the fractional part is discarded (i.e., the value is truncated toward zero ). So in the case of -10.5 , it's converted to -10 . C++11 4.9 Floating-integral conversions [conv.fpint] An rvalue of a floating point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is

passing argument makes pointer from integer

前提是你 提交于 2019-12-18 05:56:18
问题 I can't find my problem. keeps giving me these errors: "c:2:5: note: expected 'int *' but argument is of type 'int'" "c:28:1: warning: passing argument 1 of 'CountEvenNumbers' makes pointer from integer without a cast [enabled by default]" Here is the code: 1 #include <stdio.h> 2 int CountEvenNumbers(int numbers[], int length); 3 int main(void) 4 { 5 int length; 6 int X;int Z; int Y; int W; 7 X=0;Y=0;Z=0;W=0; 8 printf("Enter list length\n"); 9 scanf("%d",&length); 10 int numbers[length]; 11

Multiplying a string by an int in c++

ⅰ亾dé卋堺 提交于 2019-12-18 05:22:33
问题 What do I have to do so that when I string s = "."; If I do cout << s * 2; Will it be the same as cout << ".."; ? 回答1: No, std::string has no operator * . You can add (char, string) to other string. Look at this http://en.cppreference.com/w/cpp/string/basic_string And if you want this behaviour (no advice this) you can use something like this #include <iostream> #include <string> template<typename Char, typename Traits, typename Allocator> std::basic_string<Char, Traits, Allocator> operator *