//
//  CustomNSUtils.h
//  DemoCustomXmliOSApi
//
//  Created by sviluppo on 27/03/14.
//  Copyright (c) 2014 CUSTOM. All rights reserved.
//

#import <Foundation/Foundation.h>


#define fromUtf8(str) [[NSString alloc] initWithUTF8String:(char*)str]



@interface NSString (CustomCategory)

- (BOOL) startsWith: (NSString*)substring;
- (int) lastIndexOf: (NSString*)substring;
- (NSString *) left: (int)pos;
- (NSString *) right: (int)pos;
- (NSString *) replace: (NSString*)target :(NSString *)replacement;
- (int)toInt:(BOOL *)convOK : (int)base;
- (BOOL) endsWith: (NSString*)substring;

@property (readonly) char *toUtf8;




/*
 Returns the position of the first found occurrence of a specified value in a string.
 Returns -1 if the string is not found
 */
-(int)indexOfString:(NSString *)string;



/*
 Returns the position of the last found occurrence of a specified value in a string
 Returns -1 if the string is not found
 
 */
-(int)lastIndexOfString:(NSString *)string;



/*
 Splits a string into an array of substrings
 */
-(NSArray *)splitOnChar:(char)ch;

/*
 Splits a string into an array of substrings
 */
-(NSArray *)splitOnString:(NSString *)string;

/*
 Extracts part of a string, beginning at the character at the specified position, and returns the specified number of characters
 */
-(NSString *)substringFrom:(NSInteger)from to:(NSInteger)to;



/*
 Extracts part of a string, from beginning to the beginning of the input string.
 Returns null if not found.
 */
-(NSString *)substringToString:(NSString*)ch;



/*
 Extracts part of a string, from end to the beginning of the input string.
 Returns null if not found.
 */
-(NSString *)substringFromString:(NSString*)ch;



/*
 Joins two or more strings, and returns a copy of the joined strings
 */
-(NSString *)concat:(NSString *)string;



/*
 Removes whitespace from both ends of a string
 */
-(NSString *)trim;



/*
 Returns yes if string consists of only white spaces
 */
-(BOOL)isBlank;



/*
 Returns yes if string contains input string
 */
-(BOOL)contains:(NSString *)string;


/*
 Replaces each substring of this string that matches the given regular expression with the given replacement (This is from Java String)
 */
-(NSString *)replaceAll:(NSString *)regex replacement:(NSString *)replacement;


@end
