//
//  NSString+Utility.m
//  Minfo
//
//  Created by Nguyen Hieu on 1/3/13.
//  Copyright (c) 2013 Nguyen Hieu. All rights reserved.
//

#import "NSString+Utility.h"

@implementation NSString (Utility)
- (NSString *)stringByDecodingURLFormat {
    NSString *result = [self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
    result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    return result;
}
- (NSMutableDictionary *)dictionaryFromQueryStringComponents {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    for (NSString *keyValue in [self componentsSeparatedByString:@"&"]) {
        NSArray *keyValueArray = [keyValue componentsSeparatedByString:@"="];
        if ([keyValueArray count] < 2) {
            continue;
        }
        NSString *key = [[keyValueArray objectAtIndex:0] stringByDecodingURLFormat];
        NSString *value = [[keyValueArray objectAtIndex:1] stringByDecodingURLFormat];
        
        NSMutableArray *results = [parameters objectForKey:key];
        
        if(!results) {
            results = [NSMutableArray arrayWithCapacity:1];
            [parameters setObject:results forKey:key];
        }
        
        [results addObject:value];
    }
    
    return parameters;
}
- (NSData *)StrStringToNSdata
{
    return [self dataUsingEncoding:NSUTF8StringEncoding];
}
-(NSArray *)convertTypeToArr
{
    return [self componentsSeparatedByString:@"-"];
}
-(NSString *)AddTypeToString:(NSString *)type
{
    NSArray *ar = [self componentsSeparatedByString:@"-"];
    NSString *st = @"";
    for (int i=0;i<[ar count];i++)
    {
        NSString *str = [ar objectAtIndex:i];
        if(![str isEqualToString:type])
        {
            if(i==0)
            {
                st = [st stringByAppendingString:[NSString stringWithFormat:@"%@",str]];
            }
            else{
                st = [st stringByAppendingString:[NSString stringWithFormat:@"-%@",str]];
            }
            
        }
    }
    [st stringByReplacingOccurrencesOfString:@"--" withString:@""];
    
    return  [st stringByAppendingString:[NSString stringWithFormat:@"-%@",type]];
    
}
-(NSString *)GetCurencyWithIndex:(int)index
{
    switch (index) {
        case GzUER:
            return UER;
            break;
        case gzJPY:
            return JPY;
            break;
        case gzUSD:
            return USD;
            break;
        case gzGBP:
            return GBP;
            break;
        default:
            return USD;
            break;
    }
}




@end
