NSStringUtilities.h:

#import <Foundation/Foundation.h>
@interface NSString(Utilities)

-(BOOL) isURL;

@end

NSStringUtilities.m

#import "NSStringUtilities.h"
@implementation NSString(Utilities)
-(BOOL) isURL
{
    if ([self hasPrefix:@"http://"]) {
        return YES;
    }else{
        return NO;
    }
}
@end

main.m:

#import <Foundation/Foundation.h>
#import "NSStringUtilities.h"
int main(void)
{
    @autoreleasepool {
        NSString* string1=@"http://www.google.com";
        NSString* string2=@"Pixar";
        
        if ([string1 isURL]) {
            NSLog(@"string is a url");
        }
        if ([string2 isURL]) {
            NSLog(@"string2 is a url");
        }
    }
}

console log:

2013-09-20 12:19:54.708 Obj-c[286:303] string is a url

相关文章:

  • 2021-07-07
  • 2022-12-23
  • 2021-11-19
  • 2022-03-01
  • 2022-12-23
  • 2021-06-26
  • 2022-12-23
猜你喜欢
  • 2021-07-19
  • 2021-07-13
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案