nsstring

Concatenate int and string

被刻印的时光 ゝ 提交于 2019-11-28 01:44:49
How can I concatenate an int (e.g: 4 ) and a string (e.g: @"/12" ) for printing? I'm okay with casting the int it to an NSString format, but I don't know how I can add @"/12" after the int's value. I don't get your question, but I think you mean something like this: ...[NSString stringWithFormat:@"%d/12", intValue] 来源: https://stackoverflow.com/questions/5884367/concatenate-int-and-string

NSString method to percent escape '&' for URL

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 00:57:30
Which NSString encoding method will percent escape the ampersand ( & ) character correctly into %26 ? stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding gets the spaces (%20) and other baddies but ignores ampersands!?! Ampersands won't be processed by that method because they're legal characters in a URL. You should probably pre-process particularly problematic pieces, piecemeal, prior to this call. Thomas Desert Here is a nice solution to this problem taken from Bagonca blog to url-encode your NSStrings : + (NSString *)urlEncodeValue:(NSString *)str { NSString *result = (NSString

How can I escape unicode characters in a NSString?

痞子三分冷 提交于 2019-11-28 00:53:24
问题 When I store a NSString inside some NSDictionary and log that dictionary to the console like this: NSString *someString = @"Münster"; NSDictionary *someDict = [ NSDictionary dictionaryWithObjectsAndKeys: someString, @"thestring" ]; NSLog ( @"someDict: %@", [ someDict description ] ); The console output looks like this: unicode_test[3621:903] someDict: { thestring = "M\U00fcnster"; } with the string's unicode character escaped. Is there any method to convert a NSString to this escaped

Convert UTF-8 encoding to ISO 8859-1 encoding with NSString

为君一笑 提交于 2019-11-28 00:37:41
问题 I have an application that reads the data in UTF-8 format from the server, but it has to be displayed in ISO 8859-1(Latin-1). Are there any Cocoa APIs to achieve this? 回答1: You can use NSString 's getCString:maxLength:encoding: method, like this: char converted[([string length] + 1)]; [string getCString:converted maxLength:([string length] + 1) encoding: NSISOLatin1StringEncoding]; NSLog(@"%s", converted); Once you have this, you can then re-initialize an NSString instance from that same

NSString containing hex convert to ascii equivalent

隐身守侯 提交于 2019-11-28 00:20:21
I have an NSString that has hex information such as <00000020 66747970 4d344120 00000000 4d344120 6d703432 69736f6d 00000000 00031203 which came from NSData. What I need to do is convert that NSString of Hex data to Ascii which would be: [0][0][0] ftypM4A [0][0][0][0]M4A mp42isom[0][0][0][0][0][3][18][3] As you might be able to tell this is a M4A file. I loaded the first part of the file in to NSData using NSFileHandle. I then stored it into NSString: NSData *data = [filehandle readDataOfLength:1000]; NSString *str = [[NSString alloc]initWithString:[NSString stringWithFormat:@"%@",data]];

Find the number of characters that fits in a UITextView with constant width and height with a given string?

北城余情 提交于 2019-11-28 00:15:35
问题 In my application I need to set Read more into the text view if text input is large.so my approach is to find the range of string that would fit in the text view and append See More to it.Is there any way to achieve it in Swift.The requirement is to emulate the read more option to show the complete text in detailed view on tap like facebook. 回答1: The function you are looking for is CTFramesetterSuggestFrameSizeWithConstraints. Essentially, it allows you to find out the number of characters

How to check if NSString is numeric or not [duplicate]

孤人 提交于 2019-11-27 23:34:17
Possible Duplicate: iphone how to check that a string is numeric only I have one NSString, then i want check the string is number or not. I mean NSString *val = @"5555" ; if(val isNumber ){ return true; }else{ retun false; } How can I do this in Objective C? Use [NSNumberFormatter numberFromString: s] . It returns nil if the specified string is non-numeric. You can configure the NSNumberFormatter to define "numeric" for your particular scenario. #import <Foundation/Foundation.h> int main(int argc, char* argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLocale *l_en = [

NSString get -characters

喜欢而已 提交于 2019-11-27 23:15:57
I want to get the characters of an NSString. Like this: NSString *data; const char * typein = [[data characters] UTF8String]; But obviously NSString won't respond to -characters. How do I get the characters of NSString? thanks, Elijah mklfarha You can use this function: for(int i =0 ;i<[myString length]; i++) { char character = [myString characterAtIndex:i]; } or NSString *str = @"astring"; const char *cString = [str UTF8String]; If you just want to get a cString from the NSString just call UTF8String as you are already doing and then iterate the array. 来源: https://stackoverflow.com/questions

NSString - how to go from “ÁlgeBra” to “Algebra”

让人想犯罪 __ 提交于 2019-11-27 22:45:59
Does anyone knows hoe to get a NSString like "ÁlgeBra" to "Algebra", without the accent, and capitalize only the first letter? Thanks, RL NSString has a method called capitalizedString : Return Value A string with the first character from each word in the receiver changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values. NSString *str = @"AlgeBra"; NSString *other = [str capitalizedString]; NSLog (@"Old: %@, New: %@", str, other); Edit: Just saw that you would like to remove accents as well. You can go through a series of steps: //

How to calculate height of html string?

怎甘沉沦 提交于 2019-11-27 22:39:01
问题 I want to display html text on a label(TTStyleLabel). I am receieving text in form of html. How do I calculate height of html string? 回答1: To get height of html text you need to put that html info uiwebview. After loading the html in uiwebview you can get its height in its delegate methods like this - - (void)viewDidLoad { [super viewDidLoad]; webview.delegate = self; [webview loadHTMLString:@"<div id='foo' style='background: red'>The quick brown fox jumped over the lazy dog.</div>" baseURL