nsstring

How can i convert NSdata to hex string?

ⅰ亾dé卋堺 提交于 2019-11-29 22:57:07
问题 i tried following codes for converting a NSData to hex string values but all are wrong? here "result" is my NSdata i need a hex string as output but iam not getting that NSUInteger dataLength = [result length]; NSLog(@"%d",dataLength); NSMutableString *string = [NSMutableString stringWithCapacity:dataLength*2]; const unsigned char *dataBytes = [result bytes]; for (NSInteger idx = 0; idx < dataLength; ++idx) { [string appendFormat:@"%02x", dataBytes[idx]]; } NSLog(@"%@",string); how can i

objective-c get last 2 characters of a string?

大城市里の小女人 提交于 2019-11-29 21:15:52
Say I have a string: NSString *state = @"California, CA"; Can someone please tell me how to extract the last two characters from this string (@"CA" in this example) NSString *code = [state substringFromIndex: [state length] - 2]; should do it Swift 4: let code = (state as? NSString)?.substring(from: state.characters.count - 2) 来源: https://stackoverflow.com/questions/3483223/objective-c-get-last-2-characters-of-a-string

How to see if an NSString starts with a certain other string?

人走茶凉 提交于 2019-11-29 20:31:52
I am trying to check to see if a string that I am going to use as URL starts with http. The way I am trying to check right now doesn't seem to be working. Here is my code: NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://"]; if ([businessWebsite rangeOfString:@"http"].location == NSNotFound){ NSString *temp2 = [[NSString alloc] init]; temp2 = businessWebsite; [temp appendString:temp2]; businessWebsite = temp2; NSLog(@"Updated BusinessWebsite is: %@", businessWebsite); } [web setBusinessWebsiteUrl:businessWebsite]; Any ideas? Try this: if ([myString hasPrefix:@"http"]) .

Check NSString for special characters

走远了吗. 提交于 2019-11-29 20:18:01
I want to check an NSString for special characters, i.e. anything except a-z, A-Z and 0-9. I don't need to check how many special characters are present, or their positions, I just need to know whether a particular string contains any or not. If it does, then I want to be able to display "Error!", or something similar. For example, jHfd9982 is OK but asdJh992@ is not. Also, letters with accents, diacritics, etc. should not be allowed. How would I go about this? Thanks! Michael NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@

Check if NSString instance is contained in an NSArray

对着背影说爱祢 提交于 2019-11-29 20:06:43
I have an array with a bunch of strings and I want to check if a certain string is contained in the array. If I use the containsObject : message on the array, I'm getting correct results. Do all NSString objects with the same string point to the same object? Or why is the containsObject : working? NSArray *stringArray = [NSArray arrayWithObjects:@"1",@"2",@"3",anotherStringValue, nil]; if([stringArray containsObject:@"2"]){ //DO SOMETHING } Yes, hard-coded NSStrings (string literals) (that is any @"..." in your source code) are turned into strings that exist indefinitely while your process is

BOOL to NSString

你。 提交于 2019-11-29 19:56:41
If I have a method that returns a BOOL , how do I cast that to an NSString so I can print it out in console? For example, I tried doing this, which isn't working: NSLog(@"Is Kind of NSString:", ([thing isKindOfClass:[NSString class]]) ? @"YES" : @"NO"); But I really want to actually turn the return value into an NSString. I know it's a primitive data type, so I can't call methods on it. Do I have to create a string separately and then use the Bool as a parameter in a method on NSString? You need a formatting specifier in your format string: NSLog(@"Is Kind of NSString: %@", ([thing

iOS成员变量和属性之间区别

荒凉一梦 提交于 2019-11-29 19:31:13
OC中的成员变量和属性是不一样的 @interface Person : NSObject{ //成员变量 NSString *name; NSInteger age; } //属性 @property (nonatomic,copy)NSString *address; @property(nonatomic,assign)CGFloat height; -(void)obtainInfo; @end 属性是用@property来定义的,属性是用_address来访问的,使用@property, 系统自动生成setter和getter.如果属性只使用 @property 声明,而没使用 @synthesize 的话,系统会自动的给你声明一个 _ 开头的实例变量。如果又使用 @synthesize 的话,则相当于声明了一个实例变量, https://www.cnblogs.com/huangzs/p/7508583.html 来源: https://blog.csdn.net/qq_31214097/article/details/100899423

how to remove first 3 characters from nsstring?

天大地大妈咪最大 提交于 2019-11-29 19:25:02
I have a string like this "A. rahul VyAs" and i want to remove "A. " and the space after the "A." so that new string would be "rahul VyAs" How do i achieve this? You can use the NSString instance methods substringWithRange: or substringFromIndex: NSString *str = @"A. rahul VyAs"; NSString *newStr = [str substringWithRange:NSMakeRange(3, [str length]-3)]; or NSString *str = @"A. rahul VyAs"; NSString *newStr = [str substringFromIndex:3]; Try this, char *string=[@"A. rahul VyAs" cStringUsingEncoding:NSUTF8StringEncoding]; char *subString=&name[3]; NSString *newString=[NSString stringWithCString

How to convert a NSString to UTF-8 format string in iphone sdk?

大兔子大兔子 提交于 2019-11-29 18:51:40
问题 I have localization in my app(english,spanish,italian).The client sent me strings files but some characters are strange how do i correct them? i have figured out that the client used Mac OS Roman encoding how do i convert this to utf-8. for example Nürnberg is converted into N√ºrnberg when client send me now i want to reconvert it. 回答1: If you have a properties file with all of the strings... you can load them in and read them with any of these (from NSString's Documentation): – initWithBytes

ZKButton

拜拜、爱过 提交于 2019-11-29 18:18:00
// // ZKButton.h // WaterProofer // // Created by HELLO WORLD on 2019/9/15. // Copyright © 2019年 WaterProofer. All rights reserved. // #import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, ZKButtonType) { ZKButtonTypeLeftAndRight=0,//左右结构 ZKButtonTypeTopAndBottom=0,//上下结构 }; NS_ASSUME_NONNULL_BEGIN @interface ZKButton : UIButton @property(nonatomic,assign)ZKButtonType type; @property(nonatomic,strong)NSString* left_top_SelectImg; @property(nonatomic,strong)NSString* left_top_DefaultImg; @property(nonatomic,strong)NSString* left_top_SelectTitle; @property(nonatomic,strong)NSString* left_top