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
Related
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];
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')
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 ... }
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];
I have 2 NSArray's that are holding values...
For example NSArray 1 has values 1 2 4 in it
and NSArray 2 has values 1 2 4 5 6 in it.
How can I write code to compare these 2 arrays to get the following information...
Count the values that are the same (so in this case 3) and count the values that are not the same (in this case 2).
I am simply populating the arrays like this:
NSString *s = #"1,2,4";
NSArray *numbers = [s componentsSeparatedByString:#","];
where *s is actually getting the text from a UITextField. If sorting mattering in comparing can you show me code to sort to make sure the user doesnt put the numbers in order?
If you are fine with sets instead of arrays, you can use NSMutableSet instead of NSArray. NSMutableSet has nice methods like intersectSet: and minusSet:
I would probably use the following method of the NSArray class:
enumerateObjectsUsingBlock.
and code the block testing for membership in the other array with the method:
indexOfObjectIdenticalTo.
If this isn't clear to you let me know.