PDA

View Full Version : Pythong String format to NSString




Oblivionixx
Jul 11, 2011, 02:04 AM
Hi:
I am working on a project which I am going to implement an UI for IPad while the original UI is written in Python.
Here is a Python script written in the original UI:



msg = '%8s\0%8s\0%8s\0%s\0'(dst,code,appcode,data)
size = len(msg)+9
msg='%8s\0%s'(size,msg)



I need to make the same message and put it into the NSStream for sending to a remote server. How can I convert the script into NSString format?

Thanks.
Thanks in advance.



RonC
Jul 13, 2011, 12:04 PM
Hi:
How can I convert the script into NSString format?


I could tell you exactly what to do, but you need to learn how to do it yourself.

You should read String Programming Guide (http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/introStrings.html#//apple_ref/doc/uid/10000035i) and pay attention to the section on Formatting String Options. A couple of corresponding documents to look at are String Format Specifiers (http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1) and the IEEE printf specification (http://www.opengroup.org/onlinepubs/009695399/functions/printf.html).

You'll be able to figure it out. If you can't figure it out from those, write some code and show us what you can figure out. We can help from there, but we're not going to do your work for you.