Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to add a few strings to an array. the strings have a variable part like "test1" , "test2" , "test3" and so on. I thought using a for loop would be a good idea but i get some errors.
here is the code:
for (int i=0; i<19; i++) {
[detailImageArray addObject:#"army%#.jpg",i];
}
You can use +[NSString stringWithFormat:] method as follows:
for (int i = 0; i < 19; i++) {
[detailImageArray addObject:[NSString stringWithFormat:#"army%d.jpg",i];
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to write macro to pick up slices which I would like to include in my MIP. So far it looks like this:
LowerStack = getNumber("prompt", 10);
UpperStack = getNumber("prompt", 10);
run("Z Project...", "start=" + LowerStack) ("stop=" + UpperStack) ("projection=[Max Intensity]");
It recognizes the Lower slice which I want to pick up, but not the upper one.
Any suggestions on what do I do wrong?
The syntax of the third line is incorrect. This works:
LowerStack = getNumber("Lower", 10);
UpperStack = getNumber("Upper", 10);
run("Z Project...", "start=" + LowerStack + " stop=" + UpperStack + " projection=[Max Intensity]");
Note that I also changed the string in the two prompts because you would likely get an error by them not being unique.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I thought lroundf would round my float to the next highest number at .5 steps. E.g. 1.5f would be rounded to 2.0f.
I tried, but my code tells me otherwise:
int roundUp = 1.5f;
NSLog(#"no round up: %d", roundUp);
NSLog(#"lroundf: %ld", lroundf(roundUp));
And my output is:
no round up: 1
lroundf: 1
How do I correctly round up my float?
int rounded = lroundf(theFloat); NSLog(#"%d",rounded);
int roundedUp = ceil(theFloat); NSLog(#"%d",roundedUp);
int roundedDown = floor(theFloat); NSLog(#"%d",roundedDown);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
A custom function that will return a random number with a step option available like in the for loop.
Example:
for i=1,10,**2** do
print(i)
end
Do you mean this:
function randomWithStep(first, last, stepSize)
local maxSteps = math.floor((last-first)/step)
return first + stepSize * math.random(0, maxSteps)
end
This gives the same behavior as math.random(first, last) except that the values will be "stepSize" apart. Note that the highest random # may not be "last", depends if (last-first) is a multiple of stepSize.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If I have a BOOL that has a state of YES or NO, is there a command to flip its state?
Obviously foo=!foo; doesn't apply.
Obviously foo=!foo; doesn't apply.
foo = !foo does apply.
NO example:
BOOL foo = NO;
foo = !foo;
...foo equals YES...
And for any value other than NO:
BOOL foo = YES; // -3 or YES or 100
foo = !foo;
...foo equals NO...
If you find an API which does not return YES or NO, file a bug report. You wouldn't see that from Apple, but some people have taken advantage of the ability to store numbers other than YES or NO in a BOOL (which is a signed char -- it predates C's bool). If needed, you can reduce a BOOL to YES or NO using !!foo, (bool)foo, or bool f = foo;. I favor the last; bool variables.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have php code, where occur sort, like this:
j=0;
while(...){
...
$cancel_alarm_trusee[$j]['created'] = alarm['created'];
...
j++;
}
function Compare($a, $b) {
return $a['created'] < $b['created'];
}
usort($cancel_alarm_trusee, 'Compare');
How to do it in Ruby?
Ruby Has Enumerable#sort and Enumerable#sort_by also.Look those methods.
Example:
%w{apple pear fig}.sort_by { |word| word.length}
#=> ["fig", "pear", "apple"]
%w(rhea kea flea).sort
#=> ["flea", "kea", "rhea"]