If string contains statement - Swift 2 Xcode 7 - ios

I am using the Xcode 7 beta 5 and Swift 2. I currently have a UITextField and a UIButton. The UITextField is set to a decimal pad, but however, the user is able to enter in multiple decimals. That is not how I would like the app to work. I would like to check, when the button is tapped, if the text field has 0-1 decimal points. Is there any statement that checks for multiple decimal points?

Replace textField with a reference to your UITextField in this:
if textField.text.componentsSeperatedByString(".").count >= 3 {
// more than 1 decimal point
}
This seperates the text in the text field into an array and creates an array of strings separated on any decimal points. If there are 0-1 decimal points, the array will have less than 3 items. This documentation might be helpful.

Give the text field a delegate and implement textField:shouldChangeCharactersInRange:replacementString: to prevent the user from entering a decimal point if there is already one present.

Related

conditional format only marks one cell if the next values are the same

I am formatting a column in a way that the 2 lowest values are painted green, with the custom formula:
=K6<SMALL($K$6:$K$44; 3)
From my understanding this takes the third lowest value and paints the ones beneath that (the two lowest) green.
This worked fine until, today we had value 168, 169.5 169.5 and values above that. It only colored 168 as green although, 169.5 is the 2nd lowest value. Why does it not mark all 3 green?
Is there a way I can easily fix this ? So that it always marks the 2 lowest values, even if there are multiple of them.
You asked for conditional formatting that:
...always marks the 2 lowest values, even if there are multiple of them.
Try the following formula
=OR(K6=MIN(SORTN($K$6:$K$44,2,2,1,1)),K6=MAX(SORTN($K$6:$K$44,2,2,1,1)))
(Do adjust the formula according to your ranges and locale)
Try rank(), like this:
=rank(K6; unique(K$6:K$44); true) <= 2

Get the number of digits from label ios

I am creating labels dynamically and I want to know the number of digits entered in the label so that I can create new labels of that number. i.e. if the digit in the label is "67453848" then I have to get the number of digits in this label here it is "8".
Thank you
you looking for
label.text.length;
Use this:-
NSLog(#"%d",yourLabel.text.length);

random number not repeating [duplicate]

This question already has answers here:
Generating non-repeating random numbers
(5 answers)
Closed 9 years ago.
I use the following code to hide an UIButton from my rand_btns NSMutableArray.
int random = arc4random_uniform ([rand_btns count]);
if (random != level - 1) {
[[rand_btns objectAtIndex:random] setHidden:YES];
} else {
// call again this method
}
It works great, but ... it repeats. How can I stop repeating OR to check if an UIButton from my rand_btns array was hidden, don't need to include this objectAtIndex again.
I mean, if using my code, I can hide random button from my array excepting a specific objectAtIndex.
I would like to NOT REPEAT AGAIN THAN NUMBER from int random
You can refer to this Non-repeating arc4random_uniform. If you want to check if your button is already hidden or not, you can check button.hidden property.
If you want a random-ish sequence of numbers that doesn't repeat, one way to do it is to fill an array with consecutive numbers and then shuffle the list so that the numbers are ordered randomly. That way, you know that each number occurs only once, but you can't predict the order that the numbers appear in.
Random numbers can repeat, since they are random. You probably need to hold a list of the random numbers you have been served so far, and when you want a new number keep trying until you get a number that's not in your list. Also beware that if you're looking for a number that you haven't had so far then sooner or later you're going to run into an infinite loop as eventually there will be no more "free" numbers in the range you want

Cobol dashes are confusing me [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
cobol difference with Picture having a dash (-) and a having a X
I'm tying to get to grips with Cobol and can't understand the dashes when formatting a number. I have this example:
--9
Am I correct with the following?
The first dash - If number is a negative put a dash otherwise don't.
the second dash - I'm confused with this. There is already a dash at the start to specify whether its negative or positive.
9 - Numeric digit (0-9)
An example would be good. :S
Thanks
In view of your previous question, Im not sure what you are having trouble with. But lets try again...
In COBOL, numeric display fields may contain various types of "punctuation". This "punctuation" is defined in the items PICTURE clause. A few examples of the type of "punctuation" symbols you can use are: Explicit decimal points, plus/minus signs, CR/DR indicators and thousnads separators (commas in North America). There is a well defined set of rules that determine what type of "punctuation" can occur in the PICTURE clause and where. This link to PICTURE CLAUSE editing explains how to construct (or read) any given PICTURE clause.
One thing that you, and many others new to COBOL, trip up on is that a data definition in COBOL specifies two distinctly different types of information about numeric display data. One is the range of values it may hold and the other is how
that range of values may be displayed. Your example: PICTURE --9 tells me two things about the data item: 1) Values are integers in the range of -99 through to +99, and 2) Displaying this item will take 3 spaces. If the number is positive, spaces will appear before the first non zero digit. If the number is negative a minus sign will appear immediately to the left of the first non zero digit. Consider the following COBOL DISPLAY statement:
DISPLAY '>' DISP-NBR '<'
IF DISP-NBR has a PICTURE clause of: --9 this is how various values will be displayed.
0 displays as: > 0<
-1 displays as: > -1<
-11 displays as: >-11<
10 displays as: > 10<
Note that all displays take 3 character positions. At least 1 digit will always be displayed (because of the '9' in the PICTURE clause), other than that, no leading zeros are displayed. A minus sign will display only for negative values. The minus sign, if displayed will be to the immediate left of the first displayed digit.
Now to answer you specific question: The total number of character positions needed to display a numeric display data item is determined by the length of the PICTURE. You have a 3 character PICTURE so 3 character positions are needed. When
a sign is specified in the PICTURE, a space is always reserved for it. This is what limits the range of integers to those containing at most 2 digits. The second minus sign indicates 'zero supression'. Zero supression just means not printing leading zeros. Only 1 minus sign is ever printed and it will be to the immediate left of the first displayed digit.
COBOL contains a lot of flexability with respect to displaying numbers. Understanding the numeric display PICTURE clause is key to understanding how this all works.
from stackoverflow:cobol-difference-with-picture-having-a-dash-and-a-having-a-x
The dash means that if you have a negative number, a dash will be
shown beside (at the left) of the number. Only one dash will be
displayed. If the number is positive, a space will shown for every
dashes.

IOS: take a double value without two digits after the decimal point

I have a text field where I write a number; if I write inside this textfield a number without decimal point, I want to take this value and add a decimal point and two number after it
if I write (in textfield) "1" , I want to add ",00" then it becomes 1,00
if I write "1,8" , It becomes : "1,80"
or
if I write "2,86", It don't change : "2,86"
when I solve it I want to add this value in an array.
You should have a look into NSNumberFormatter.

Resources