nsstring

How to remove hexadecimal characters from NSString

北城余情 提交于 2019-12-05 13:49:20
I am facing one issue related some hexa value in string, i need to remove hexadecimal characters from NSString. The problem is when i print object it prints as "BLANK line". And in debug mode it shows like : So how can i remove it from the string? EDIT Triming whitespace : result of NSLog is : 2015-12-14 15:37:10.710 MyApp [2731:82236] tmp :'' Database: Earlier question: how to detect garbage string value in ios? As your dataset clearly has garbage values, You can use this method to check if your string is valid or not. Define your validation criteria and simply don't entertain the values

Objective-C how to check if a string is null

主宰稳场 提交于 2019-12-05 13:31:37
问题 SO I wish to check to see if the item in my array [clientDataArray objectForKey:@"ClientCompany"] is nil . temp = [clientDataArray objectForKey:@"ClientCompany"]; if (temp != [NSNull null]) infofieldCompany.text = temp; So far I have been able to achieve this through the above code, but it does give me the warnings warning: NSArray may not respond to -objectForKey: warning: comparison of distinct Objective-C types struct NSNull * and struct NSString * lacks a cast My main interest is the

convert base64 decoded NSData to NSString

烂漫一生 提交于 2019-12-05 13:30:19
I'm trying to encode and decode base64 data. but while decoding the base64 data, it returns bunch of hex values, but i couldn't display or printout using NSlog to the original readable strings. The below code couldn't print anything, just empty. Can anyone help ? thanks > > NSString* msgEncoded = [[NSString alloc] initWithFormat:@"Q1NNKE1DTC9TTUEgUkNWL2FkbWluQHNldGVjcy5jb20gT1JHLyBUVkIvNDNkYzNlMzQwYWQ3Yzkp:"]; NSData* decoded = [[NSData alloc] initWithData:[self decodeBase64WithString:msgEncoded]]; NSString* plainString = [[NSString alloc]initWithData:decoded encoding:NSUTF8StringEncoding];

Remove part of an NSString

感情迁移 提交于 2019-12-05 12:37:24
I have an NSString as follows: <img alt="996453912" src="http://d2gg0uigdtw9zz.cloudfront.net/large/996453912.jpg" /><a href="http://www.dealcatcher.com/shop4tech-coupons">Shop4Tech Coupons</a> I only need the first part (before the <a href part), and I cannot figure out how to remove the second part. I have tried a ton, but it has not worked. Use something like: NSRange rangeOfSubstring = [string rangeOfString:@"<a href"]; if(rangeOfSubstring.location == NSNotFound) { // error condition — the text '<a href' wasn't in 'string' } // return only that portion of 'string' up to where '<a href' was

NSString stringWithFormat is slow

南楼画角 提交于 2019-12-05 12:26:18
In Objective-C, the method stringWithFormat: seems to be extremely slow and is actually a large bottleneck in one of our apps (we used the profiler to find that out). Is there a way to optimise it or use some faster C code? Yes use sprintf in c http://www.cplusplus.com/reference/cstdio/sprintf/ after that push the char* in a NSString with [NSString stringWithUTF8:]; example: char cString[255]; sprintf (cString, "%d", 36); NSString* OCstring = [[NSString alloc] initWithUTF8String:cString]; If you're doing extensive string manipulations and operations - it sounds like you might well be doing so,

How to join two strings for NSPredicate, ie firstname and lastname

有些话、适合烂在心里 提交于 2019-12-05 12:26:07
问题 I have a Person Object which has two NSString properties; firstName and lastName . I'm currently using an NSPredicate like so: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName contains[cd] %@) OR (lastName contains[cd] %@)", searchText, searchText]; So, for example, say I'm searching for the name "John Smith" . In my search bar if I type "Joh" , then John Smith will appear as an option. This is good and fine, but if I type in "John Sm" it will go blank. How can I join

NSString stringwithformat: Padding 2 strings with unknown length

末鹿安然 提交于 2019-12-05 11:43:54
I'm having a problem doing something with NSString stringWithFormat... The problem is as follows: First of all, I have 2 strings. Which are money quantities. The thing, is that i want to create 1 string with these two. For ex: strF = [NSString stringWithFormat:@"First: %@ Second: %@", value1, value2]; I want to know if there is possible to make a correct padding between First and Second.. Assuming the first string is not the same length always.. I want to make this: First: 10,000.00 Second: 788.00 First: 10.00 Second: 788.00 First: 0.00 Second: 788.00 First: 100.00 Second: 788.00 First: 5.00

How do I get class from NSString?

半腔热情 提交于 2019-12-05 10:36:26
for example, I have NSString *myClass = @"RootViewController" How do I get class from NSString? Try this id obj= [[NSClassFromString(@"RootViewController") alloc] init]; You can use Class class = NSClassFromString(@"RootViewController"); NSClassFromString Obtains a class by name. Class NSClassFromString ( NSString *aClassName ); Parameters aClassName The name of a class. Return Value The class object named by aClassName, or nil if no class by that name is currently loaded. If aClassName is nil, returns nil. Availability Available in iOS 2.0 and later. There is a lot of methods like this in

How to convert a JSON String into an NSArray? [closed]

风格不统一 提交于 2019-12-05 09:53:02
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am facing an issue while converting an NSString to NSArray. My string is : ["Default", "Discipleship", "Faith", "Family", "Hope", "Life Building", "Love", "Missions", "Relationships"] What i want to do is get the elements(Default,Discipleship etc.) out of this string and put them into an NSArray. I have tried a lot but couldn't get it done, please help Any help would be great , thanks in advance First you

Get the NSString height in iOS 7 [duplicate]

我的梦境 提交于 2019-12-05 09:52:11
This question already has an answer here: Replacement for deprecated sizeWithFont: in iOS 7? 20 answers I am using the below code to calculate the height of a label from string length. Im using xcode 5.0 and it works fine in iOS 6 simulator but it's not working well in iOS 7. NSString* str = [[array objectAtIndex:i]valueForKey:@"comment"]; CGSize size = [className sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; Height_1 = size.height; If there is any solution for iOS 7 then please help. Thanks in Advance Well here is