nsstring

How do I convert a NSString into TIS-620 encoded string

In the apple document, I can see that there's a way to convert from UTF8 string to ASCII string like this NSData *asciiData = [theString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *asciiString = [[NSString alloc] initWithData:asciiData encoding:NSASCIIStringEncoding]; But my app requires a TIS-620 stri...

Is there a difference between NSString compare: and isEqual(ToString): ?

Occasionally I find code which tests if two NSStrings are the same like this: if ([str1 compare:str2] == NSOrderedSame) { // Do something } Now, I believe this is less readable than using isEqualToString: and it also has some nasty side effects, like if str1 == nil the if(..) evaluates to true, or when str2 == nil havoc might brea...

iPhone: How to Extract a Numerical Value from a String?

Is it possible to extract a number from a string. For example, I have a string: my name is shishir and my number is 98890876478 Can I extract on 98890876478 from the above string? Or if my string is: my name is shishir and my number is XXX98890876478XXX In this condition can I extract `98890876478", which is in between of XXX. Is...

static NSStrings in Objective-C

I frequently see a code snippet like this in class instance methods: static NSString *myString = @"This is a string."; I can't seem to figure out why this works. Is this simply the objc equivalent of a #define that's limited to the method's scope? I (think) I understand the static nature of the variable, but more specifically about ...

Adding different save data to one file

I'm stuck at one of the last parts of my iApp, can someone help me? I want to add different field entries of different .m files into one file without overwriting the file. (I also dont know how to make that save file btw). I have 2 .h files with : file1 : NSString *dataHML; NSString *dataHML2; file2 : NSString *dataHML3; ...

Troubles with NSString writeToFile

Hi everyone, I have been working on a simple text editor in Cocoa/Objective-C for a practice project and I have come across an error that I would never have expected. I have an NSString for my file's contents as well as an NSString for it's path. When I attempt to write the contents to a file, I use the following method: [FileContents...

Specific Strings And NSScanner

I need to determine whether a string (sourceString) contains another string (queryString) and if it does, at what offset. I'm guessing that NSScanner might do the trick but I don't fully understand the documentation. Let's say sourceString = @"What's the weather in London today?" If I set queryString to equal @"What's the weather", I...

Crashing Strings.... :( objective-c

I have in the .h file : NSString *dataHML; NSString *dataHML2; NSString *dataHML3; NSString *dataHML4; NSString *dataHML5; NSString *dataHML6; NSString *dataHMLtotal; in the .m file i merge them with : NSString *dataHtmlTotal = [NSString stringWithFormat:@"%@%@%@%@%@%@", dataHtml, dataHtml2, dataHtml3, dataHtml4,dataHtml5,dataHtml6]...

Objective-C Syntactical Question

Just doing some research on searching for a character or word within a NSString and I came across this code snippet (which works like a charm): return [sourceString rangeOfString:searchString].location != NSNotFound; Am I right in thinking that the above code is functionally identical to: NSRange range = [sourceString rangeOfString:s...

NSStrings created without alloc, memory leaks

My app is riddled with memory leaks concerning NSString objects. Never, ever do I use alloc to create an NSString object, yet according to Instruments (used with a real device) the app leaks NSString objects. This happens around uses of stringByAppendingString. Example of code: NSString *documentsPathPlusSlash = [self.documentsPath stri...

NSString , EXC_BAD_ACCESS and stringByAppendingString

Hi, i wrote the following code : NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSDictionary *reportDic = [jsonparser objectWithString:json_string error:nil]; NSDictionary *reporttable = ...

Passing a string representing my format specifier into stringWithFormat and seeing issues

If I call "[NSString stringWithFormat:@"Testing \n %@",variableString]"; I get what I would expect, which is Testing, followed by a new line, then the contents of variableString. However, if i try NSString *testString = @"Testing \n %@"; //forgive shorthand here [NSString stringWithFormat,testString,variableString] the output actually ...

iPhone SDK. How to assign NSString to UILabel text ?

If I have a class/object like this #import <Foundation/Foundation.h> @interface anObject : NSObject { NSString *aProp; } @property NSString aProp; @end and in the cellForRowAtIndexPath method i want to assign one of the string values from its properties to a uilabel of a tableviewcell, how do i do it? I've tried this but it do...

NSString: fastes way of splitting

Hey, my question is a performance question. I need to split a huge NSString into coordinates. The string has this format: @"coordx,coordy coordx,coordy coordx,coordy (...)" My method to parse this is: -(NSMutableArray*) parsePath:(NSString*) pathString { // first split between the coordinates NSArray* path = [pathString com...

Best way to initialise / clear a string variable cocoa

I have a routine that parses text via a loop. At the end of each record I need to clear my string variables but I read that someString = @"" actually just points to a new string & causes a memory leak. What is the best way to handle this? Should I rather use mutable string vars and use setString:@"" between iterations? ...

Can't append space at end of UITextView

I have a UITextView in which I want the initial value to be "@username " when they keyboard shows up (notice the space after the username). This way the user can start typing right away without having to tap space. So I do: textView.text = [NSString stringWithFormat:@"@%@ ", username]; But it seems like it's impossible to have the UIT...

NSString Backslash escaping

Hi, I am working on an iPhone OS application that sends an xml request to a webservice. In order to send the request, the xml is added to an NSString. When doing this I have experienced some trouble with quotation marks " and backslashes \ in the xml file, which have required escaping. Is there a complete list of characters that need to...

objective c NSURL may not respond to +initFileURLWithPath

I have two lines of code in the applicationDidFinishLaunching function: NSString *targetFilePath = @"/Users/bob/Documents/About_Stacks.pdf"; NSURL *targetFileURL = [NSURL initFileURLWithPath:targetFilePath]; and I am getting the warning (title) in the second line... I have no idea what I am doing wrong. This is an absurdly simply app...

Format a date from a string

Hey. I'm trying to format a date from a string into another format. For example: 2012-05-29 23:55:52 into 29/05 *newline* 2010. I just don't get the logics behind NSDate and NSDateFormatter, I think.. Any help will be appreciated. Thanks :) ...

NSString sizeWithFont: returning inconsistent results? known bug?

I'm trying to create a simple custom UIView wich contain a string drawn with a single font, but where the first character is slightly larger. I thought this would be easily implemented with two UILabel:s placed next to eachother. I use NSString sizeWithFont to measure my string to be able to lay it out correctly. But I noticed that th...