mond
mond

Reputation: 38

Is there any way to check a string for additional characters?

Is there any way to check a string for additional characters?

[buffer rangeOfString:@"\n"]

I get an input string and need to check if it contains any additional character like [{}Ҧ Is it possible to check this with one command? Is there a way like in java to do this? If one character is wrong in the whole buffer i need to do something.

 for(int i = 0; i < buffer.lenght;i++){
    if(buffer[i] < Z && buffer[i] >a){
       do something cool...
    }
    else System.exit();
}

this code is not correct just to show up what i mean.

Upvotes: 0

Views: 29

Answers (1)

Jesse Rusak
Jesse Rusak

Reputation: 57168

I'm not sure what you mean by "additional characters" but if you mean punctuation, you can do something like:

if ([buffer rangeOfCharacterFromSet:[NSCharacterSet punctuationChracterSet]].location != NSNotFound)

Or if you mean "non letter" you can say:

if ([buffer rangeOfCharacterFromSet:[[NSCharacterSet letterCharacterSet] invertedSet]].location != NSNotFound)

Upvotes: 2

Related Questions