1. Create a File for Objective - C Category and Click the Next Button
2. Type a Name for Category and Select the Category on NSString and Click the Create Button.
3. The File is created as Category Type. The File Name like as NSString+Name
4. Write the Below Codes
NSString+Name.h File
#import <Foundation/Foundation.h>
@interface NSString (Validate)
-(NSString *)checkthestring:(NSString *)string_value;
-(NSString *)checkanotherstring:(NSString *)str_value;
-(NSString *)nullcheck:(NSString *)string_null_value;
-(int)getLength:(NSString*)string_length;
@end
NSString+Name.m File
#import "NSString+Validate.h"
@implementation NSString (Validate)
-(NSString *)checkthestring:(NSString *)string_value
{
// Special Characters
string_value = [string_value stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n\r"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"\\r" withString:@"\n\r"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"“" withString:@"'"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"”" withString:@"'"];
string_value = [string_value stringByReplacingOccurrencesOfString:@" " withString:@""];
string_value = [string_value stringByReplacingOccurrencesOfString:@"«" withString:@"<<"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"»" withString:@">>"];
string_value = [string_value stringByReplacingOccurrencesOfString:@""" withString:@"\""];
string_value = [string_value stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
string_value = [string_value stringByReplacingOccurrencesOfString:@">" withString:@">"];
// ISO 8859-1 Symbols
string_value = [string_value stringByReplacingOccurrencesOfString:@"¡" withString:@"¡"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¢" withString:@"¢"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"£" withString:@"£"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¤" withString:@"¤"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¥" withString:@"¥"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¦" withString:@"¦"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"§" withString:@"§"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¨" withString:@"¨"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"é" withString:@"é"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ª" withString:@"ª"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"«" withString:@"«"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¬" withString:@"¬"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"­" withString:@" "];
string_value = [string_value stringByReplacingOccurrencesOfString:@"®" withString:@"®"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¯" withString:@"¯"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"°" withString:@"°"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"±" withString:@"±"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"²" withString:@"²"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"³" withString:@"³"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"´" withString:@"´"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"µ" withString:@"µ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¶" withString:@"¶"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"·" withString:@"·"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¸" withString:@"¸"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¹" withString:@"¹"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"º" withString:@"º"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"»" withString:@"»"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¼" withString:@"¼"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"½" withString:@"½"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¾" withString:@"¾"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"¿" withString:@"¿"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"×" withString:@"×"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"÷" withString:@"÷"];
// ISO 8859-1 Characters
string_value = [string_value stringByReplacingOccurrencesOfString:@"À" withString:@"À"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Á" withString:@"Á"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Â" withString:@"Â"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ã" withString:@"Ã"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ä" withString:@"Ä"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Å" withString:@"Å"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Æ" withString:@"Æ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ç" withString:@"Ç"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"È" withString:@"È"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"É" withString:@"É"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ê" withString:@"Ê"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ë" withString:@"Ë"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ì" withString:@"Ì"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Í" withString:@"Í"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Î" withString:@"Î"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ï" withString:@"Ï"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ð" withString:@"Ð"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ñ" withString:@"Ñ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ò" withString:@"Ò"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ó" withString:@"Ó"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ô" withString:@"Ô"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Õ" withString:@"Õ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ö" withString:@"Ö"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ø" withString:@"Ø"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ù" withString:@"Ù"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ú" withString:@"Ú"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Û" withString:@"Û"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ü" withString:@"Ü"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Ý" withString:@"Ý"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"Þ" withString:@"Þ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ß" withString:@"ß"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"à" withString:@"à"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"á" withString:@"á"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"â" withString:@"â"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ã" withString:@"ã"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ä" withString:@"ä"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"å" withString:@"å"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"æ" withString:@"æ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ç" withString:@"ç"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"è" withString:@"è"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"é" withString:@"é"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ê" withString:@"ê"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ë" withString:@"ë"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ì" withString:@"ì"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"í" withString:@"í"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"î" withString:@"î"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ï" withString:@"ï"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ð" withString:@"ð"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ñ" withString:@"ñ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ò" withString:@"ò"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ó" withString:@"ó"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ô" withString:@"ô"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"õ" withString:@"õ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ö" withString:@"ö"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ø" withString:@"ø"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ù" withString:@"ù"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ú" withString:@"ú"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"û" withString:@"û"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ü" withString:@"ü"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ý" withString:@"ý"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"þ" withString:@"þ"];
string_value = [string_value stringByReplacingOccurrencesOfString:@"ÿ" withString:@"ÿ"];
return string_value;
}
-(NSString *)checkanotherstring:(NSString *)str_value
{
str_value = [str_value stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n\r"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"\\r" withString:@"\n\r"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"\\r" withString:@"\n\r"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"“" withString:@"'"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"”" withString:@"'"];
str_value = [str_value stringByReplacingOccurrencesOfString:@" " withString:@""];
str_value = [str_value stringByReplacingOccurrencesOfString:@"«" withString:@"<<"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"»" withString:@">>"];
str_value = [str_value stringByReplacingOccurrencesOfString:@""" withString:@"\""];
str_value = [str_value stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
str_value = [str_value stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
str_value = [str_value stringByReplacingOccurrencesOfString:@">" withString:@">"];
return str_value;
}
-(NSString *)nullcheck:(NSString *)string_null_value
{
if ( [string_null_value isEqualToString:@""] || string_null_value.length == 0 || [string_null_value isEqualToString:@"<null>"] || string_null_value == NULL)
{
NSLog(@"Value is Empty");
string_null_value = @"Value is Empty";
}
NSLog(@"%@", string_null_value);
return string_null_value;
}
-(int)getLength:(NSString*)string_length
{
int length = string_length.length;
return length;
}
@end
//** The code has been placed some other .m file **//
SomeFile.m
-(void)replaceSpecialCharacters
{
int Country;
NSString *Replace_String = @"";
sqlite3_stmt * Replace_String_pdt_statement;
// Country for code: India-8 Europe-4 (English Language)
// It’s No Need to Encode Strings.
if ( Country == 4 || Country == 8 )
{
// Without Encode the String - Used for Special Characters, ISO 8859-1 Symbols & ISO 8859-1 Characters
Replace_String = [NSString stringWithFormat:@"%s", sqlite3_column_text(Replace_String_pdt_statement, 1)];
NSLog(@"%@", Replace_String);
Replace_String = [Replace_String checkthestring:Replace_String];
}
// Country for code: Other are Chinese, Korean & Japanese.
// It’s Supported only Encode Strings.
else
{
// With Encode the Characters - Used for Only Special Characters
Replace_String = [NSString stringWithCString:(char *)sqlite3_column_text(Replace_String_pdt_statement, 1) encoding:NSUTF8StringEncoding];
NSLog(@"%@", Replace_String);
Replace_String = [Replace_String checkanotherstring:Replace_String];
int length = [Replace_String getLength:Replace_String];
NSLog(@"%d", length);
}
}
No comments:
Post a Comment