Articles Tagged 'parseInt ()'

Objective-C: type conversion

With some high-level languages ​​such as JavaScript or PHP, where the data are not typed or otherwise can not be, we are "spoiled" in compare or convert strings and integers and vice versa, all hidden or manipulated by the interpreter (or compiler ). For example, in JavaScript functions are "forced" (like parseInt() for example) required in special cases. However, in other circumstances we treat without worrying about a particular integer conversions (explicit), such as:

1
2
3
5 ; mioNumero var = 5;
/ / ...
"Il valore di mioNumero è " + mioNumero ) ; alert ("The value of mioNumero is" + mioNumero);

In Objective-C, however, the data type is important and the type conversion must be explicit. Besides the casting (better typecasting) we can use the features and functionality specific to the type conversion. For example, here is how to convert an integer to a string:

1
2
3
4
5 ; mioNumero int = 5;
miaStringa = [ NSString stringWithFormat : @ "%d" , mioNumero ] ; NSString * myString = [ NSString stringWithFormat: @ "% d", mioNumero];
/ /
"miaStringa=%@ mioNumero=%i" , miaStringa, mioNumero ) ; NSLog (@ "myString = @ mioNumero% =% i", myString, mioNumero);

In contrast, here is how to convert a string to an integer:

1
2
3
4
miaStringa = @ "128" ; NSString * myString = @ "128";
[ miaStringa integerValue ] ; mioNumero int = [myString integerValue];
/ /
"miaStringa=%@ mioNumero=%i" , miaStringa, mioNumero ) ; NSLog (@ "myString = @ mioNumero% =% i", myString, mioNumero);

Continued ...

Very short snippet: Actionscript extend an array by the method shuffle ()

I had already talked about how to implement the method shuffle () in Javascript and Actionscript . I realized, tuttaavia, not pointing out that it is able to extend Actionscript, Javascript in the same way, its object Array :

Continued ...

Very short snippet: shuffle () in Javascript and Actionscript

In PHP there is a handy feature called shuffle() that allows you to mix an array (see Very short trick: take random elements from an array in PHP ). An excellent version of the javascript I found here . Slightly revised the code below:

Continued ...