Lefora Free Forum
Loading
540 views

is a character already in the range

Page 1
1–3
rookie - member
1 posts

Hi everybody! I need to get, is a character already in the range. The character string is of type NSMuttableString. 
For example, I have a string of "52.648" and I need to know is a "." symbol is already in the string. How can I do it? Thanx!

?
63 posts


I think this from here will help you.

NSString* floatString = @"12.345";
NSRange dotRange = [floatString rangeOfString:@"."];
if (dotRange.loc = NSNotFound && dotrange.len = 0) {
    NSLog(@"floatString doesn't contain .");
} else {
    NSLog(@"floatString contains .");
}

__________________
kompilesoft

come and see my website! it's real cool reviews
?
288 posts

There are many methods in the NSString class for searching strings.  You'll find the documentation here:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

You can find the position of a substring with:
NSRange r = [string  rangeOfString:@"."];
if ( r.location != NSNotFound ) {
    bla bla bla
}

If you're simply wanting to convert that string to a double you can use the doubleValue method (and or intValue/longValue, boolValue floatValue for atoi type conversion).

double d = [string doubleValue];

If you know the stardard C library functions (strlen,strstr and so on), you can use them:
char* theBytes [string UTF8String];
if ( strchr(theBytes,'.') ) {
  bla bla;
}

I do NOT recommend using the C library functions, however they might help you transition from the familiar land of C to the much more charming (and slightly mysterious) world of Objective-C and Cocoa.

__________________
Page 1
1–3

Locked Topic


You must be a member to post in this forum

Join Now!