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 02-21-2011, 08:32 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Chicago, IL
Posts: 15
Gefthebest is on a distinguished road
Default if char in "=-)(*&^%$#..."

Hi all,

I was wondering if there was an easy was to check if there were special characters in a string..

In python programming language I know you can do:
for chars in someString:
if chars in "-)(*&^%^%$##@@;':,.":
do something...

It would basically be to check for special characters in a string and alert the user that they are not allowed...

Thanks
Gefthebest is offline   Reply With Quote
Old 02-21-2011, 09:36 PM   #2 (permalink)
Registered Member
 
Objective Zero's Avatar
 
Join Date: Oct 2010
Posts: 1,210
Objective Zero is on a distinguished road
Default

How about this?
Code:
-(NSString*) replaceBadWords:(NSString*)userText {
    NSArray  *badWordsArray= [NSArray arrayWithObjects:@"!", @"@", @"#", @"$", nil];
	
    for(NSString* s in badWordsArray){
		userText =[userText stringByReplacingOccurrencesOfString:s withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[userText length])];
    }
	
    return userText;
}
userText is the NSString
Objective Zero is offline   Reply With Quote
Old 02-21-2011, 10:09 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Chicago, IL
Posts: 15
Gefthebest is on a distinguished road
Default

Hm, I just read about the for each loop and I thought of using it... But its just really code consuming to have to write an array with all the special characters in...
I might find a way using the ASCII code starting first special character and incrementing until the last one...

But I wished there was an easy function like in python...

Thanks for the help
Gefthebest is offline   Reply With Quote
Old 02-21-2011, 10:12 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Take a look at NSCharacterSet.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-22-2011, 07:35 AM   #5 (permalink)
Applesnaps
 
Join Date: Oct 2009
Location: Almere, The Netherlands
Posts: 7
Applesnaps is on a distinguished road
Default

Quote:
Originally Posted by Gefthebest View Post
Hi all,

I was wondering if there was an easy was to check if there were special characters in a string..

In python programming language I know you can do:
for chars in someString:
if chars in "-)(*&^%^%$##@@;':,.":
do something...

It would basically be to check for special characters in a string and alert the user that they are not allowed...

Thanks
For more advanced options use a regular expression. Just drag and drop .h and .m file from RegexKitLite or any other regex framework and of you go.
Applesnaps is offline   Reply With Quote
Reply

Bookmarks

Tags
char, chars, string, strings

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: 383
17 members and 366 guests
Absentia, apatsufas, BinHex, cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, mottdog, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

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