objective c how to add string value to integer? [duplicate] - objective-c

This question already has an answer here:
How do I append a string/number to a string ?
(1 answer)
Closed 6 years ago.
I have label and I want to give it value of two elements that one of them NSInteger and the other string
_imgIndex.text = [#(index+1) stringValue]; //how to add string here?

It appears that you have an integer value (index) and a Obj-C string object (stringValue) and you want to concatenate them. There are lots of ways of doing this, here are two:
_imgIndex.text = [NSString stringWithFormat:#"%lu%#",index,stringValue];
The other technique would be to first convert the integer into a string, then concatenate the other string:
_imgIndex.text = [#(index).description stringByAppendingString:stringValue];

Related

ms access: simple subtraction, wrong answer [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 3 years ago.
181.72 - 181.00 = 0.719999999999999
Why does Access do this? How can I get the correct answer of 0.72
Always use Currency as data type (also for your table fields) for amounts and quantities that require no more than four decimals:
Result = CCur(181.72) - CCur(181.00)
Result -> 0.72
For more decimals, use Decimal:
Result = CDec(181.59898) - CDec(181.00)
Result -> 0.59898
For use in a query, CDec will fail, so write a function to call it:
Public Function CVDec(ByVal Value As Variant) As Variant
Dim Result As Variant
Result = CDec(Value)
CVDec = Result
End Function

Converting a String or base10 to a base 2 in VB [duplicate]

This question already has answers here:
Quickest way to convert a base 10 number to any base in .NET?
(12 answers)
Closed 9 years ago.
I am looking for a way to take a value from a text box and convert it into a base 2 number with 8 digits.So if they type in a text box 2 it would respond 00000010. or if they typed 255 11111111. etc... is there any way to do this.
Dim prVal As Integer
prVal = PrefixTxt.Text
Use the Convert.ToString method and specify the base as 2. This will convert an Integer value into a String in the specified base
Dim result = Convert.ToString(Integer.Parse(prVal), 2)
As #Dan pointed out if you want to force this to be width 8 use the PadLeft method
result = result.PadLeft(8, "0"c)
Convert.ToString(Integer.Parse(prVal), 2).PadLeft(8, '0')

How to compare two NSNumber numbers? [duplicate]

This question already has answers here:
Comparing NSNumbers in Objective C
(5 answers)
Closed 9 years ago.
So, in my previous question (check out this > If-else: NSString) I've known how to check two strings. But now my task is compare two numbers.
isEqualToNumber isn't I need. For example: if the first number has a value 13, the second value has a value 20. How to compare these numbers?
Thank you everyone. Which method do I should use?
My code:
NSNumber *foo1 = #13;
NSNumber *foo2 = #14;
I need to compare them:
if ( foo1 < foo2) {
//some actions
}
if ([foo1 compare:foo2] == NSOrderedAscending) { ... some actions ... }

how to add percent sign to string [duplicate]

This question already has answers here:
How to add percent sign to NSString
(7 answers)
Closed 9 years ago.
Sorry I'm a bit new to objective c and I can't find out how to do something as simple as include a percent sign in a string. How is this accomplished in objective c?
Here's what I tried:
NSString *string = #"%";
brightnessLabel.text = [NSString stringWithFormat:[#"Brightness: %.0f" stringByAppendingString:string],slider.value];
but the percent doesn't show up. Thanks for the help.
You need to use "%%". So like this:
NSString *string = #"%%";
If you want a number with a percent after it:
brightnessLabel.text = [NSString stringWithFormat:#"Brightness: %.0f%%", slider.value];

Concatenate strings on Objective C [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I concatenate strings in Objective-C?
Hello everyone I am new to Objc, I want to concatenate strings of the Integer value with string value.
Here is my code:
[runtime setText:[NSString stringWithFormat:#"%#",self.movie.runtime]];
The result will be: 120
The result that I wish to concatenate string is: 120 Minutes.
Please share me about this.
Thanks
I guess, you want this
[runtime setText:[NSString stringWithFormat:#"%# Minutes",self.movie.runtime]];
while concatenating would be:
NSString *newString = [aString stringByAppendingString:anotherString];
for immutable NSStrings
and
[aMuteableString appendString:anotherString];
for NSMutableStrings