Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 21, 2012, 02:22 AM   #1
themacster298
macrumors member
 
Join Date: Feb 2011
Exclude words?

New to programming here and need some help.

How would I go about excluding words when someone enters one in a text field?

For example, if someone types "My favorite number is 32". How would I exclude everything other than the number to store it in a variable with a push of a button?
themacster298 is offline   0 Reply With Quote
Old Apr 21, 2012, 02:28 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
There are lots of ways to do this ranging from the naive to natural language processing. If you are new to programming I would recommend changing the design of your interface such that "My favorite number is:" is a label, and you have a field that only accepts a number.

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 21, 2012, 02:41 PM   #3
themacster298
Thread Starter
macrumors member
 
Join Date: Feb 2011
Quote:
Originally Posted by lee1210 View Post
There are lots of ways to do this ranging from the naive to natural language processing. If you are new to programming I would recommend changing the design of your interface such that "My favorite number is:" is a label, and you have a field that only accepts a number.

-Lee
Thanks for the tips, but I am actually interested in doing it the other way. Thanks for the help, though
themacster298 is offline   0 Reply With Quote
Old Apr 21, 2012, 02:56 PM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
OK. Is that EXACTLY the phrase they'll enter? Do you just want the LAST word at the end of the sentence? Any number that appears? The fifth word that is entered?

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 21, 2012, 03:04 PM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
The general documentation you should read is the "String Programming Guide". It has sections on searching and scanning strings, as well as a lot of other stuff.

That guide should also be in the builtin Xcode documentation (use Xcode's Help menu to open the doc window, then search for String Programming Guide).


To solve the problem, Break It Down.

Step 1: How do you distinguish the number part of the text from the non-number part?

Maybe look at the NSCharacterSet class, and see what it has for identifying decimal digits. Then you'd be able to classify individual characters in the text as "part of a number" and "not part of a number".


Step 2: How do you access individual characters in the text, so they can be classified as "part of a number" and "not part of a number"?

See the NSString class, and look for methods that return a character at a specific index, or characters in a range.

Also look at NSString methods that let you scan and search an NSString for characters in an NSCharacterSet, and which returns the ranges of those characters.


Step 3: Having access to the ranges or individual characters of the text, and being able to distinguish number-parts from non-number-parts, you now have sufficient information to extract the parts that are the number-part and the non-number-part. Put each part into a separate NSString. Done.

Or see the NSScanner class. You should already be familiar with NSString and NSCharacterSet, or it won't make much sense.


The overall strategy is basic problem solving. Break it down, describe it in plain language, repeat. Keep applying that (breaking it down, describing it plainly), until you have clearly described problems that are easy enough to solve without further breaking them down.

Every program is an explanation. It explains to the computer exactly how to solve the problem. If you can't explain things, or don't understand what you're solving, or can't break things down, you won't be able to write programs.

Last edited by chown33; Apr 21, 2012 at 03:11 PM.
chown33 is offline   0 Reply With Quote
Old Apr 21, 2012, 03:47 PM   #6
themacster298
Thread Starter
macrumors member
 
Join Date: Feb 2011
Quote:
Originally Posted by lee1210 View Post
OK. Is that EXACTLY the phrase they'll enter? Do you just want the LAST word at the end of the sentence? Any number that appears? The fifth word that is entered?

-Lee
In a way, yes. I am creating a trading tool for my friend for a game called "team fortress 2". This was the instructions he gave me:

Quote:
TF2Scanner:

1. Enter steam ids into text box
2. Press button to begin scanning
3. Somehow exclude the rest of the text and only leave the steam id. (Probably put it in a variable such as: tf2items.com/items/%i (%i being the steamid)
4. Show players starting with lowest hours first, with a link to their backpack.

Example of steam ID:
# 454 "R1ky" STEAM_0:0:25395679 05:20 90 0 active
As you can see, I only want to grab the "STEAM_0:0:1234567" part, but I have no way of doing this.

(Also, this is not a phisher, hacker, it is a TRADING tool much like this one)
themacster298 is offline   0 Reply With Quote
Old Apr 21, 2012, 04:38 PM   #7
itickings
macrumors 6502a
 
itickings's Avatar
 
Join Date: Apr 2007
Quote:
Originally Posted by themacster298 View Post
As you can see, I only want to grab the "STEAM_0:0:1234567" part, but I have no way of doing this.

(Also, this is not a phisher, hacker, it is a TRADING tool much like this one)
Am I understanding you correctly? You want to make a tool to single out the least experienced players, and list what can be stolen from them?
Wow, just … wow.

And here you are, expecting people to do the work for you because you are inexperienced and don't know so much about programming?
How ironic.
__________________
Rawr!
itickings is offline   0 Reply With Quote
Old Apr 21, 2012, 05:01 PM   #8
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
I can't comment on what this is being used for, but if the format you posted is exact it seems easy enough to tokenize on spaces and grab the third token. I'm guessing there's a fixed format for Steam IDs, but Valve might not publish it. If you did know this you could write something more flexible that searched for tgus format.

How easy any of this is depends on the language and possibly libraries you're using. Which are you using? It doesn't matter that much, but if this is for-pay you might mention it, as that's a bit sticky if someone wrote a lot of this for you.

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 21, 2012, 06:51 PM   #9
themacster298
Thread Starter
macrumors member
 
Join Date: Feb 2011
Quote:
Originally Posted by itickings View Post
Am I understanding you correctly? You want to make a tool to single out the least experienced players, and list what can be stolen from them?
Wow, just … wow.

And here you are, expecting people to do the work for you because you are inexperienced and don't know so much about programming?
How ironic.
No, I am not stealing anything from anyone. Programs like this is to find useful items that you want for useful items other people want. I thought this would be a fun and challenging thing to do as a first project and just happened to run into a small problem. Sorry for this misconception.

EDIT: Finally figured it out. Thanks for the help everyone!
themacster298 is offline   0 Reply With Quote
Old Apr 22, 2012, 05:31 AM   #10
elppa
macrumors 68040
 
elppa's Avatar
 
Join Date: Nov 2003
When I glanced at this the other day I thought the easiest solution was a regex. Im surprised no one suggested it.
elppa is offline   0 Reply With Quote
Old Apr 22, 2012, 11:11 AM   #11
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by elppa View Post
When I glanced at this the other day I thought the easiest solution was a regex. Im surprised no one suggested it.
Maybe because no one knew what language he was writing in. And still, no one does.

Or maybe because he wrote: "New to programming here ...", and he wouldn't know a regex from a ... well, anything. So now you have two problems.
chown33 is offline   0 Reply With Quote
Old Apr 22, 2012, 11:56 AM   #12
elppa
macrumors 68040
 
elppa's Avatar
 
Join Date: Nov 2003
Quote:
Originally Posted by chown33 View Post
Maybe because no one knew what language he was writing in. And still, no one does.

Or maybe because he wrote: "New to programming here ...", and he wouldn't know a regex from a ... well, anything. So now you have two problems.
That's part of the reason I didn't reply. No language was mentioned.

And “new to programming” doesn't mean you couldn't work out a simple regex if it was explained.
elppa is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Tar do not take --exclude into account sandy-locke Mac Programming 3 Jan 16, 2013 01:39 PM
Road Words - (Type words while dodging traffic!) [FREE] jswiney iPhone and iPod touch Apps 0 Dec 12, 2012 04:15 PM
Exclude iTunes from TM Backup AppleDApp OS X 10.8 Mountain Lion 5 Nov 3, 2012 01:33 PM
Time machine: How to choose instead of exclude? TijmenDal Mac Applications and Mac App Store 2 Aug 26, 2012 02:26 PM

Forum Jump

All times are GMT -5. The time now is 07:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC