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 07-10-2010, 05:43 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Location: Los Angeles, Ca
Posts: 27
Jrman52 is on a distinguished road
Default Problem trying to translate “+” into character +

I'm having a problem trying to convert a character into a string in Xcode. Here's my code...

NSString *temp = [NSString stringWithFormat:@"%@ %@ %@ = %@", inputOne.text, sign.text, inputTwo.text, answer.text];

self.sign.text is suppose to return either a "+", "-", "*", or "/", which it does. However, I'm trying to have the user post one of these back into facebook via the app. All but the "+" sign will load as a string when they post it to their wall. I don't understand how to get the "+" to show.

I'm guessing that this gets lost since the "+" has a different meaning in javascript. How can I make it a string character in my NSString so that it accepts when posting. Hope this made sense.
Jrman52 is offline   Reply With Quote
Old 07-10-2010, 09:28 PM   #2 (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 Jrman52 View Post
I'm having a problem trying to convert a character into a string in Xcode. Here's my code...

NSString *temp = [NSString stringWithFormat:@"%@ %@ %@ = %@", inputOne.text, sign.text, inputTwo.text, answer.text];

self.sign.text is suppose to return either a "+", "-", "*", or "/", which it does. However, I'm trying to have the user post one of these back into facebook via the app. All but the "+" sign will load as a string when they post it to their wall. I don't understand how to get the "+" to show.

I'm guessing that this gets lost since the "+" has a different meaning in javascript. How can I make it a string character in my NSString so that it accepts when posting. Hope this made sense.
How are you posting your string to Facebook? Is it sending it up in an HTTP URL? If so, you need to escape characters like "+", "-", or "/". I'm not sure about "*".


Code:
CFStringRef charsToEscape = CFSTR("&=+-/");

- (NSString *)stringByAddingPercentEscapesToString: (NSString*) source
{ 
  return [(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, 
    (CFStringRef) source, NULL, charsToEscape, 
    CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease]; 
}
__________________
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 07-11-2010, 03:22 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Location: Los Angeles, Ca
Posts: 27
Jrman52 is on a distinguished road
Default

Well here's what i'm trying to do...

Code:
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = @"Example prompt";
dialog.attachment = @"{\"name\":\"1/2 + 1/2 = 1 or 1/1\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
// replace this with a friend's UID
// dialog.targetId = @"999999";
[dialog show];
The equation i have there has a + sign in it, and when I try posting it to facebook, it doesn't show. Any other sign I have no problem with. I even tried using the \ to see if it would let it thru. I'm still a beginner, so I'm trying to understand the code you just sent me. I'm so thankful for your response. Based on the code above, do you think there is an easier way to do it?
Jrman52 is offline   Reply With Quote
Old 07-11-2010, 07:02 AM   #4 (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 Jrman52 View Post
Well here's what i'm trying to do...

Code:
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = @"Example prompt";
dialog.attachment = @"{\"name\":\"1/2 + 1/2 = 1 or 1/1\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
// replace this with a friend's UID
// dialog.targetId = @"999999";
[dialog show];
The equation i have there has a + sign in it, and when I try posting it to facebook, it doesn't show. Any other sign I have no problem with. I even tried using the \ to see if it would let it thru. I'm still a beginner, so I'm trying to understand the code you just sent me. I'm so thankful for your response. Based on the code above, do you think there is an easier way to do it?
Since you are sending your equation to Facebook embedded in an HTTP URL, characters that are used as delimiters in a URL (Like "+/?=&") may get mis-interpreted as part of the "punctuation" of the URL "sentence" rather than part of the content you are putting inside the URL. The convention for handling this to "escape" the characters that cause problems. That means converting them to the form "%xx", where xx is their ASCII value, in hexadecimal. The code I posted will find characters in a block of text and convert the characters defined at the beginning, plus some others, into their escaped form.

If you do a google search for "ASII table" you'll find this ASCII table. (link) That shows that the hex value of a plus sign is 2B. So first, just try putting your plus signs into your equation manually as "%2B".

It looks like the equation you are sending is inside quotes, so I'm a little puzzled as to why it would need to be escaped, but I would try it anyway.
__________________
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 07-11-2010, 12:54 PM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Location: Los Angeles, Ca
Posts: 27
Jrman52 is on a distinguished road
Default

Thanks Ducan. Still a no go though. When I try that, it eliminates the % and the B and just puts out the 2. So this is what you see, "1/2 2 1/2 = 1 or 1/1. Didn't think it would be this hard to get the + sign to work.

Let me correct myself, it work for twitter but not Facebook. It's so odd, what could the facebook code have that is not working. Thanks again for yor help.

Last edited by Jrman52; 07-11-2010 at 01:10 PM. Reason: Part of the code worked
Jrman52 is offline   Reply With Quote
Old 07-11-2010, 02:13 PM   #6 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: ΏLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by Jrman52 View Post
...When I try that, it eliminates the % and the B and just puts out the 2. So this is what you see, "1/2 2 1/2 = 1 or 1/1. Didn't think it would be this hard to get the + sign to work...
Are you passing the string "%2B" as any part of a string formatter? If so, the receiving formatting function will think it's a format specification. If this is the case, you need to make a change to let the function know what this "%2B" really is by "escaping" the "%" that you want to be a literal "%" in the output. This is done by doubling up the "%" character, like this: "%%2B".
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Old 07-11-2010, 02:57 PM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Location: Los Angeles, Ca
Posts: 27
Jrman52 is on a distinguished road
Default

Awesome, that worked! Thanks to both of you for all your help. I'm still learning alot of this stuff so it hard to find answers sometimes for questions like this. This is extremely appreciated.

One more question. How long does it take a developer to create a game? Can it be done by one person? Examle, Doodler (the current game in the top 5 in the app store). I can do my own art for a game I'm thinking of creating, just wondering if it can be done by me alone in a timely manner. Thanks in advance guy.
__________________
Eliseo C
Jrman52 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, javascript, objective-c

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: 326
15 members and 311 guests
akphyo, alexP, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, mariano_donati, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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