Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-19-2010, 12:46 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 71
Coolio098 is on a distinguished road
Default String Spacing

Hey everyone!

I can't exactly what this is called but I use to use it a lot in c programming. Take the following code for example:

Code:
NSString *cellID = [NSString stringWithFormat:@"%@      %@/%@   Weight:%@", [object2 objectAtIndex:0], [object2 objectAtIndex:1], [object2 objectAtIndex:2], [object2 objectAtIndex:3]];
Now basically I was there to be a fixed number of spaces for each string that is entered into cellID. If i'm not mistaken, in c programming you would do something like %8@ to have 8 spaces set for the string. How would you do this in xcode?
Coolio098 is offline   Reply With Quote
Old 09-19-2010, 02:06 PM   #2 (permalink)
Registered Member
 
msencenb's Avatar
 
Join Date: May 2009
Location: Stanford, CA
Posts: 291
msencenb is on a distinguished road
Default

Objective-C is a strict superset of the c programming language so c functions should work just fine (you may just have to convert from c-string eventually)
__________________
I'm starting a new blog dedicated to iOS development. Check it out at:

http://www.iosdevscreencasts.com
msencenb is offline   Reply With Quote
Old 09-19-2010, 02:32 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 71
Coolio098 is on a distinguished road
Default

Quote:
Originally Posted by msencenb View Post
Objective-C is a strict superset of the c programming language so c functions should work just fine (you may just have to convert from c-string eventually)
Thanks for the reply! I've tried the method that I mentioned above but no luck. Do you know the proper terminology or what the code would be to achieve what I am trying to do?
Coolio098 is offline   Reply With Quote
Old 09-19-2010, 05:17 PM   #4 (permalink)
Fly-by-night Innovator
 
Join Date: Jun 2010
Posts: 364
musicwind95 is on a distinguished road
Default

The number-based system that you described only worked (and still works) for numerical values, not strings. For simple spacing, use the \t escape sequence. Most likely though, there will be a better option for spacing—what are you trying to do?

Note that iOS's default font is not monospace—that is, spaces are not guaranteed to make things line up, unlike in the Console.
__________________
If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!


For more iOS Development, check out my blog—Cups of Cocoa. All visitors welcome, but especially beginners!

Hope I have helped!

Please check out IceFall, a new action game available in the App Store!
musicwind95 is offline   Reply With Quote
Old 09-19-2010, 07:17 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Coolio098 View Post
Thanks for the reply! I've tried the method that I mentioned above but no luck. Do you know the proper terminology or what the code would be to achieve what I am trying to do?
As the other poster says, Objective C is a true superset of C.

You can use C libraries and C strings, and then copy the results to an objective C string object. You should use pure C library functions if you want the exact same behavior, not NSString formatted string methods.

Also as the other poster says, the field size you're talking about is for numbers, and I'm pretty sure it doesn't work for strings.

Note that it would be trivial to create a method padToSize that would take an NSString as input and return a string padded to a specified length:

Code:
- (NSString*) padString: (NString*) sourceString toLength: (NSInteger) length;
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-20-2010, 11:18 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 71
Coolio098 is on a distinguished road
Default

Thanks for the responses everyone. Basically what I'm trying to do is I have a tableView and I'm looking to line up all of the data that is inputted. I'm not sure if I have to make columns in the table or how I would do this.

For example:
Code:
Test             78%       2/3
Assignment        5%       6/10
Exam             10%       9/20
That's how i'm trying to organize my cells. Any idea?

Last edited by Coolio098; 09-20-2010 at 11:20 AM.
Coolio098 is offline   Reply With Quote
Old 09-20-2010, 12:15 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 24
silverpie is on a distinguished road
Default

Quote:
Originally Posted by Coolio098 View Post
Thanks for the responses everyone. Basically what I'm trying to do is I have a tableView and I'm looking to line up all of the data that is inputted. I'm not sure if I have to make columns in the table or how I would do this.

For example:
Code:
Test             78%       2/3
Assignment        5%       6/10
Exam             10%       9/20
That's how i'm trying to organize my cells. Any idea?
This is an issue I'm pondering myself. I think what you'll want to do is make custom cells, with three labels: one on the left, left-justified, for the category; one in the middle, right-justified, for the percentage; and one on the right, (can you do justification on a character in a UILabel? if not, then just right-justified), for the fraction. Others feel free to chip in with better ideas and/or the code to implement that one.
silverpie is offline   Reply With Quote
Old 09-20-2010, 02:53 PM   #8 (permalink)
Fly-by-night Innovator
 
Join Date: Jun 2010
Posts: 364
musicwind95 is on a distinguished road
Default

Yes, a custom cell would be the only (or at least the most feasible, by far) way to go. Yes, you can set the justification in a label—it's an option under the first inspector in IB. Check out the Customizing Cells page at ADC.
__________________
If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!


For more iOS Development, check out my blog—Cups of Cocoa. All visitors welcome, but especially beginners!

Hope I have helped!

Please check out IceFall, a new action game available in the App Store!
musicwind95 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 308
14 members and 294 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:59 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0