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 10-14-2010, 10:46 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 8
DaanB is on a distinguished road
Question Need help on text!

Hello,

I'm new to the SDK, and need some help! I learned how to change a label after the user types something in a textfield. But is it possible to only show the text that a user types between two "."s

So if a user types: Hello i need .help. please
It will only display: help

Please let me know if this is possible and how.

Greets,
Daan
DaanB is offline   Reply With Quote
Old 10-14-2010, 10:57 AM   #2 (permalink)
Banned
 
Join Date: Jul 2009
Posts: 576
Not_Appy_At_All is on a distinguished road
Default

Quote:
Originally Posted by DaanB View Post
Hello,

I'm new to the SDK, and need some help! I learned how to change a label after the user types something in a textfield. But is it possible to only show the text that a user types between two "."s

So if a user types: Hello i need .help. please
It will only display: help

Please let me know if this is possible and how.

Greets,
Daan

Yes, it can be done.

You need to take the string the user types, and use the various string modifiers to edit out the parts you don't need. It will involve using mutablestrings and/or appendstring...There are various commands that will enable you to do what you want.

Once isolated, you can drop the "help" into the label.

Unfortunately I don't have a link for you...but a Google search will find them.
Not_Appy_At_All is offline   Reply With Quote
Old 10-14-2010, 11:02 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 8
DaanB is on a distinguished road
Default

Quote:
Originally Posted by Not_Appy_At_All View Post
Yes, it can be done.

You need to take the string the user types, and use the various string modifiers to edit out the parts you don't need. It will involve using mutablestrings and/or appendstring...There are various commands that will enable you to do what you want.

Once isolated, you can drop the "help" into the label.

Unfortunately I don't have a link for you...but a Google search will find them.
Thanks for your help, as i said i'm a beginner so i will have to search google. If anyone has i good link or explanation please tell me
DaanB is offline   Reply With Quote
Old 10-14-2010, 11:09 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 DaanB View Post
Hello,

I'm new to the SDK, and need some help! I learned how to change a label after the user types something in a textfield. But is it possible to only show the text that a user types between two "."s

So if a user types: Hello i need .help. please
It will only display: help

Please let me know if this is possible and how.

Greets,
Daan
Daan,

Of course it's possible. It's simple programming.

You would need to write code that looked for two periods, extracted the text between those periods, and then assigned the results to the label.

Take a look at the methods in NSString that handle searching and breaking strings into substrings. Specifically, look at the methods rangeOfString and componentsSeparatedByString.

You could use code like this:


Code:
NSString* userText = userTextField.text;
NSArray* subStrings = [userText componentsSeparatedByString: @"."];
if ([subStrings count] == 3) //user string contains exactly 2 periods, and that text delimits strings
{
  NSString* stringInsidePeriods = [subStrings objectAtIndex: 1]; //Get the second substring
  if ([stringInsidePeriods length] > 0)
    displayLabel.text =  stringInsidePeriods;
}
If the user entered
string1.string2.string3

The code above would put "string2" into the label displayLabel.
It assumes you have 2 IBOutlets in your code, one a UITextView or UITextField called userTextField and the other a UILabel called displayLabel.

If the user entered
string1..string2
or
string1.string2.string3.string4

It would not change the label, because there are checks to make sure the string is only broken into 3 pieces with periods, and that the second piece of text is not empty.
__________________
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 10-14-2010, 11:11 AM   #5 (permalink)
Banned
 
Join Date: Jul 2009
Posts: 576
Not_Appy_At_All is on a distinguished road
Default

Quote:
Originally Posted by DaanB View Post
Thanks for your help, as i said i'm a beginner so i will have to search google. If anyone has i good link or explanation please tell me
Found it for you...

Try this link....

Working with String Objects in Objective-C - Techotopia
Not_Appy_At_All is offline   Reply With Quote
Old 10-14-2010, 11:14 AM   #6 (permalink)
Banned
 
Join Date: Jul 2009
Posts: 576
Not_Appy_At_All is on a distinguished road
Default

Thanks Duncan.
Not_Appy_At_All is offline   Reply With Quote
Old 10-15-2010, 09:59 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 8
DaanB is on a distinguished road
Default

Thank you both very much for the great help! Duncan, thanks for you're code and the explanation on it!
DaanB is offline   Reply With Quote
Reply

Bookmarks

Tags
label, text, textfield

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: 351
7 members and 344 guests
Desert Diva, dre, hain, HemiMG, lendo, mottdog, oceanlablight
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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