nsstring

Objc EXC_BAD_ACCESS when setting a NSString equal to another

别等时光非礼了梦想. 提交于 2019-12-22 10:29:04
问题 I'm having some really REALLY weird issues with NSString. When I read from an input stream and convert the data to a string I'm not able to set anything equal to that string. Here's the code: NSString *name = r.URL.lastPathComponent; NSString *data; NSInputStream *stream = r.HTTPBodyStream; uint8_t byteBuffer[1]; [stream open]; if (stream) { // Get the request body from the stream. Used for setting the file name if (stream.hasBytesAvailable) { NSInteger bytesRead = [stream read:byteBuffer

Date from String using NSDateFormatter regardless 12h-24h setting

北慕城南 提交于 2019-12-22 09:39:56
问题 Today my question is about date formats and strings. My application downloads some strings representing dates from the internet. The date format is always like this: "2010-05-24 at 20:45" I need to convert this string into an NSDate object in order to perform some date manipulations. I tried this code: NSString * dateString = @"2010-05-24 at 20:45" // actually downloaded from the internet NSDateFormatter * myDateFormatter = [[NSDateFormatter alloc] init]; [myDateFormatter setDateFormat:@"yyyy

Convert String of Hex to NSString of text?

谁说我不能喝 提交于 2019-12-22 07:57:09
问题 I need to convert an NSString of hex values into an NSString of text (ASCII). For example, I need something like: "68 65 78 61 64 65 63 69 6d 61 6c" to be "hexadecimal" I have looked at and tweaked the code in this thread, but it's not working for me. It is only functional with one hex pair. Something to do with the spaces? Any tips or sample code is extremely appreciated. 回答1: Well I will modify the same thing for your purpose. NSString * str = @"68 65 78 61 64 65 63 69 6d 61 6c";

Get the NSString height in iOS 7 [duplicate]

巧了我就是萌 提交于 2019-12-22 06:46:13
问题 This question already has answers here : Replacement for deprecated sizeWithFont: in iOS 7? (20 answers) Closed 5 years ago . 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

Get result from shell script objective-c

我与影子孤独终老i 提交于 2019-12-22 00:53:52
问题 I would like to run a shell script, from a file or from an objective-c string (within the code). I would also like the shell script's result to be stored to a variable. I would not like the shell script to be split into arguments (such as setLaunchPath when I run it). For example: running this shell script "mount_webdav idisk.mac.com/mac_username /Volumes/mac_username" instead of "/bin/mount_webdav" then the arguments. Is there anyway to do this? I am using NSTask right now, but it has caused

How to find matching words in two separate strings?

。_饼干妹妹 提交于 2019-12-22 00:28:09
问题 If there are two separate strings, we need to retrieve all words that are matching (in those strings), in an array. also this matching should be case insensitive. What will be the most efficient way to achieve this. For Example: NSString *s1 = @"Hello there, I want to match similar words."; NSString *s2 = @"Do you really want to match word, hello?"; The resulting array should contain, "hello", "want", "to", "match" . I went through many questions and, responses over the net like Regular

Split string into parts

∥☆過路亽.° 提交于 2019-12-22 00:23:41
问题 I want to split NSString into array with fixed-length parts. How can i do this? I searched about it, but i only find componentSeparatedByString method, but nothing more. It's also can be done manually, but is there a faster way to do this ? 回答1: Depends what you mean by "faster" - if it is processor performance you refer to, I'd guess that it is hard to beat substringWithRange: , but for robust, easy coding of a problem like this, regular expressions can actually come in quite handy. Here's

Limiting NSString to numbers as well as # if chars entered. (code included)

青春壹個敷衍的年華 提交于 2019-12-22 00:11:47
问题 I have searched the site for my answer, however I think it is also how I got myself into this problem. I'm trying to limit my 1 and only text field to 10 characters and only numbers. Below is code mostly off other questions on this site. What I am trying to do is mash this code together for my limits - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *cs = [[NSCharacterSet

How do you join an NSArray of [Number numberWithChar: c]'s into an NSString?

▼魔方 西西 提交于 2019-12-21 22:18:02
问题 When I use componentsJoinedByString , I just get a long string of digits. Edit: I realize this task is confusing. Why on earth would anyone populate an NSArray with NSNumbers if they wanted an NSString? The answer is that I'm writing an extensible unit test framework. The basic functions genNum , genBool , and genChar generate NSNumbers with random int, BOOL, and char values respectively. Then there's genArray which generates a random array using a specified generator. So to construct a

Cocoa - Calling a variadic method from another variadic one (NSString stringWithFormat call)

微笑、不失礼 提交于 2019-12-21 20:48:32
问题 I have a problem with [NSString strigWithFormat:format] because it returns an id, and I have a lot of code where I changed a NSString var to an other personal type. But the compiler does not prevent me that there are places where a NSString is going to be set into another type of object. So I'm writing a category of NSString and I'm goind to replace all my calls to stringWithFormat to myStringWithFormat . The code is : @interface NSString (NSStringPerso) + (NSString*) myStringWithFormat: