Layth Spartan
Layth Spartan

Reputation: 11

type conversion and string reformatting (python vs. objective-c)

I am trying to do some conversion using Objective-C, I have a good experience in Python, it is very easy to convert types in python, I can change a string of numbers to integer easily, or I can even change the representation at the print statement, here are some examples:

self.workingMaskInt[index] = int(self.workingMaskListSplit[index])

self.workingMaskInt is a string of numbers, like "123", here I can convert it to integer instantly. Similarly formatting at the print statements or basically reformat some strings:

'{:08b}.{:08b}.{:08b}.{:08b}'.format(self.workingIP[0], self.workingIP[1],
                                                          self.workingIP[2], self.workingIP[3])

where self.workingIP is a list of integers, here we are reformatting it into binaries.

How can I do these format techniques and type conversions in ObjC, I searched yet couldn't find the required methods?

Upvotes: 0

Views: 178

Answers (1)

zaph
zaph

Reputation: 112857

There is no built-in binary format specifier, a table of the supported specifiers can be found here. So for a binary format you will have to code your own.

For string formatting of NSStrings you can use one of several NSString methods such as:

+ (id)stringWithFormat:(NSString *)format, ...
- (id)initWithFormat:(NSString *)format ...
- (NSString *)stringByAppendingFormat:(NSString *)format ...

Upvotes: 0

Related Questions