Develop
2014.05.12 16:43
[ios] URL 파라미터 파싱~
Views 3742 Comment 0
URL 파라미터 파싱하는..
URLParser.h
@interface URLParser : NSObject @property (nonatomic, retain) NSArray *variables; @property (nonatomic, retain) NSArray *keys; - (id)initWithURLString:(NSString *)url; - (NSString *)valueForVariable:(NSString *)varName; @end
URLParser.m
@implementation URLParser - (id) initWithURLString:(NSString *)url{ self = [super init]; if (self != nil) { NSString *string = url; NSScanner *scanner = [NSScanner scannerWithString:string]; [scanner setCharactersToBeSkipped: [NSCharacterSet characterSetWithCharactersInString:@"&?"]]; NSString *tempString; NSMutableArray *keys = [NSMutableArray new]; NSMutableArray *vars = [NSMutableArray new]; //ignore the beginning of the string and skip to the vars [scanner scanUpToString:@"?" intoString:nil]; while ([scanner scanUpToString:@"&" intoString:&tempString]) { [vars addObject:[tempString copy]]; [keys addObject: [[tempString componentsSeparatedByString:@"="] objectAtIndex:0]]; } self.variables = vars; self.keys = keys; } return self; } - (NSString *)valueForVariable:(NSString *)varName { for (NSString *var in self.variables) { if ([var length] > [varName length]+1 && [[var substringWithRange:NSMakeRange(0, [varName length]+1)] isEqualToString:[varName stringByAppendingString:@"="]]) { NSString *varValue = [var substringFromIndex:[varName length]+1]; return varValue; } } return nil; } - (void) dealloc{ self.variables = nil; self.keys = nil; } @end
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
897 | Develop |
[js] jQuery 셀 병합
1 ![]() |
hooni | 2014.09.23 | 3567 |
896 | Database | [mysql] 중복데이터 삭제하는 초간단 쿼리 | hooni | 2017.11.22 | 3572 |
895 | System/OS |
[android] 초간단 HTTP, POST 전송 샘플
1 ![]() |
hooni | 2017.02.16 | 3659 |
894 | Etc |
영어. 불규칙 동사 정리
![]() |
hooni | 2017.10.04 | 3674 |
893 | Develop | [ios] 유용한 매크로 | hooni | 2014.03.26 | 3703 |
892 | Develop | [ios] UIWebView 캐쉬 삭제 | hooni | 2014.04.08 | 3712 |
» | Develop | [ios] URL 파라미터 파싱~ | hooni | 2014.05.12 | 3742 |
890 | Develop |
[ios] SQLite 사용하기(튜토리얼) + 샘플코드
![]() |
hooni | 2014.03.28 | 3755 |
889 | Develop | [ios] iOS에서 디바이스 종류 알아오기 | hooni | 2014.05.24 | 3764 |
888 | Develop |
[ios] iOS 의 인앱구매 소개
![]() |
hooni | 2014.04.29 | 3906 |
887 | Develop |
[php] 3 Ways to Detect Mobile or Desktop in PHP
![]() |
hooni | 2020.01.28 | 3999 |
886 | Develop | [ios] UDID 사용 제한에 따른 대안들 | hooni | 2014.03.13 | 4024 |