Monday, 21 March 2016

String properties in iOS (Objective C)


  • Length
  • UTF8String
  • Capitalised a String
  • Uppercase 
  • Lowercase
  • Double Value
  • Float Value
  • Integer Value
  • Bool Value

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSString *str=[[NSString alloc]init];
        str=@ "Akshay sarda";
        NSLog(@ "%@",str);
        
        char *arr="Akshay";
        NSString *temp=[[NSString alloc]initWithCString:arr encoding:NSUTF8StringEncoding];
        NSString *a=[[NSString alloc]initWithUTF8String:arr];
        NSLog(@ "%@ %@",a,temp);
        
        int count;
        NSString *arr1=[[NSString alloc]initWithFormat:@ "Count is %d",count];
        NSLog(@ "%@",arr1);
        
        //String Length
        NSLog(@ "Length is %lu",str.length);
        NSLog(@ "Length is %lu",a.length);
        
        //UTF8String
        NSLog(@ "String is %s",temp.UTF8String);
        
        //Capitalized a String
        NSLog(@ "%@",str.capitalizedString); //It will Capitalized the First letter of each word.
        
        //Lower case String
        NSLog(@ "%@",a.lowercaseString);
        
        //Upper case String
        NSLog(@ "%@",str.uppercaseString); //It will convert the complete string in Capital Letter.
        
        //Double Value
        NSString *pi=@ "3.14";
        NSLog(@ "%f",pi.doubleValue);
        
        //Float Value
        NSLog(@ "%f",pi.floatValue);
        
        //Integer Value
        NSLog(@ "%lu",pi.integerValue);
        
        //BOOL Value
        BOOL k=YES;
        NSLog(@ "%d",k);
    }
    return 0;
}

No comments:

Post a Comment

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...