Exponential number to long value in Objective-C [closed] - ios

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to convert a string representing an exponential number to a long value. Anyone having any ideas how can I do this conversion in Objective-C?
My exponential number is "9.91350253E8"

NSString *str = #"9.91350253E8";
NSDictionary *l = [NSDictionary dictionaryWithObject:#"." forKey:NSLocaleDecimalSeparator];
NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:str locale:l];
NSLog(#"%lld", [number longLongValue]);
Try this.

You can use like this -
NSString *str=#"9.91350253E8";
long temp = str.longLongValue ;
NSLog(#"long-%ld",temp);

Related

split NSString given a number of characters in objective C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have two strings that are taken as input from a textfield in my application. I know that they are both 4 characters in length.
Is there some way I can "halve" those strings, and create two strings per original string that have two characters each?
Sure. NSString has the very useful methods "substringToIndex:" and "substringFromIndex:". The magic number (index) here appears to be 2.
A simple approach would be to use the NSString substringWithRange: method to obtain each of the pairs of characters you require.
For example:
NSString *sourceString = #"ABCD";
assert([sourceString length] == 4); // Handle error conditions here.
NSString *firstSection = [sourceString substringWithRange:NSMakeRange(0,2)];
NSString *secondSection = [sourceString substringWithRange:NSMakeRange(2,2)];
See the NSString class reference for more information.

takes this string message as an input and returns a corresponding value in terms of a number [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
For instance 1 is made of 2 dashes, 8 is made of 7 dashes and so on.write a function that takes this string message as an input and returns a corresponding value in terms of a number. This number is the count of dashes in the string message.
String has a count method:
"abc--de-f-".count('-') #=> 4
Just get a string with nothing but the dashes from your input string, and then check the length of that string:
dash_string = input_string.gsub(/[^-]/, '')
number = dash_string.length
You might want to subtract 1 from that answer based on your examples, bearing in mind that a string with no dashes would turn into -1 in that case.

Integer formatter for string ios [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to know what will be the result of the following code
NSString *str = #"0";
NSString *str1 = #"12";
NSLog(#"str int value %d, %d",str, str1);
Result I got is 18036, 18052
I used a wrong format specifier in my code and came across this weird result. I fixed it later through. But I wanted to know what exactly it print out.
Thanks
NSLog(#"str int value %d, %d",str, str1);
You're passing pointers to strings as the parameters, but the format string specifies integers. A good guess is that the pointers will be interpreted as integers, so the output will depend on where in memory the strings happen to be allocated.
I guess it printed out the string pointer address

Randomly output text from array to view - RAILS [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Randomly output text from array to view - RAILS
It is not really well formated question ... You should be more precise about what you want, what you are using, etc.
Assuming you are using Rails 3, ERB for HTML generation:
# in your controller:
file_as_array = IO.readlines('filename.txt')
random_line = rand(file_as_array.size)
#my_random_string = file_as_array[random_line]
# in your view:
<%= #my_random_string %>

How to break the line inside the brackets [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to be able to break the line inside the brackets without having the "inconsistant brackets" error.
Here's a example:
select.someclass.something{data: {max_amount: o.max_amount_clean, max_amount: o.min_amount_clean, fee: o.fee_clean}}
Thanks
I'm not sure if I understand, but if the argument is a hash and not a block, like it seems, you could do
select.someclass.something(
{data:
{max_amount: o.max_amount_clean,
max_amount: o.min_amount_clean,
fee: o.fee_clean}}
)

Resources