nsstring

How to convert NSString to char?

Hi, I'm trying to convert an NSString to a single char. When I write [[NSLocale] currentLocale] objectForKey:NSLocaleDecimalSeparator], I get @",". How can I convert this to ','? Thank you! ...

NSString drawAtPoint/drawInRect: Append "..." to truncated string

Hi, I am drawing a NSString using drawAtPoint (drawInRect, that makes no big difference). There is a parameter to set the line break mode, but has anyone an idea how to append "..." to strings if they are truncated? One option is, to check whether the string is short enough. If that is not the case, iteratively remove the last characte...

objective c 101 (retain vs assign) NSString

A 101 question Let's say i'm making database of cars and each car object is defined as: #import <UIKit/UIKit.h> @interface Car:NSObject{ NSString *name; } @property(nonatomic, retain) NSString *name; Why is it @property(nonatomic, retain) NSString *name; and not @property(nonatomic, assign) NSString *name; I understand that A...

UIPasteboard - cannot copy text

This code should copy the string to the generalPasteboard, as the [[UIPasteboard generalPasteboard] string] object, but the method causes the program to terminate. - (void)copyResultToPasteboard { NSString *message = self.resultTextView.text; [UIPasteboard generalPasteboard].string = message; [message release]; } I think i...

Description to return just ClassName?

The default description for a class instance returns "ClassName: 0x105120". How might I modify the method below to just return the "ClassName"? // The code below just returns the address ... - (NSString *)description { NSString *result; result = [NSString stringWithFormat:@"%p", self]; return result; } EDIT: in that case woul...

AES Encryption for an NSString on the iPhone

Can anybody point me in the right direction to be able to encrypt a string, returning another string with the encrypted data? (I've been trying with AES256 encryption.) I want to write a method which takes two NSString instances, one being the message to encrypt and the other being a 'passcode' to encrypt it with - I suspect I'd have to ...

Defining String Literals?

Can anyone confirm this for me ... NSString *testString = @"Betty"; By my way of thinking this line is declaring the NSString pointer (*testString) to point to the string literal @"Betty". This declaration does not need an alloc, nor does it need to be released? I just want to make sure I am on the right track. -gary- ...

NSData to NSString converstion problem!

Hi guys, I'm getting an html file as NSData and need to parse it to extract some info. My approach was to convert it to NSString with UTF8 encoding (the html has non english characters, russian for example) - it failed. I used something like that: NSString *respData = [NSString stringWithUTF8String:[theData bytes]]; but it returned n...

How can I split a string without separator?

I need to split string without a separator. Here is the code.. myarray = [mystring componentsSeparatedByString:@","]; Here I used separator "," to split string, but I want to split without using a separator NSString *mystring =@"123456"; I have this value , now I want to insert that value in an array like this: array[0]=1; array[...

NSData to NString conversion problem

I'm getting an HTML file as NSData and need to extract some parts of it. For that I need to convert it to NSString with UTF8 encoding. The thing is that this conversion fails, probably because the NSData contains bytes that are invalid for UTF8. I have tried to get the byte array of the data and go over it, but each time I come across no...

Encrypted NSData to NSString in obj-c?

I have an iPhone app which encrypts an inputted NSString using CCCrypt (AES256) and a plaintext key. The string and key are given to the encryption method which returns an NSData object. Requesting [data description] where 'data' is the encrypted string data gives an NSString like: "<0b368353 a707e7de 3eee5992 ee69827e e3603dc2 b0dbbc0b...

How to "pass on" a variable number of arguments to NSString's +stringWithFormat:

I would like to write a function in Objective-C such as the one below, that takes a variable number of arguments, and passes those arguments on to +stringWithFormat:. I know about vsnprintf, but that would imply converting the NSString 'format' to C and back (and would also mean converting the formatting placeholders within it as well......

Help adding string inside alert view

I have a sting that is equal to a text field that i want to insert inside of a UIAlertView. NSString *finalScore = [[NSString alloc] initWithFormat:[counter2 text]]; UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:finalScore message:@"You scored X points" ...

How to convert an NSString into an NSNumber

Hello, How can I convert an NSString containing a number of any primitive data type (e.g. int, float, char, unsigned int, etc.)? The problem is, I don't know which number type the string will contains at runtime. I have an idea how to do it, but I'm not sure if this works with any type, also unsigned and floating point values: long lo...

Detecting binary vs. "human readable" plist file for iPhone

I'm trying to programmatically determine if an iPhone Info.plist is an ASCII (or UTF-8 or UTF-16) file, or, a binary file. I've been investigating the [NSString stringWithContentsOfFile:encoding:error] and I've tried multiple different encodings, including NSASCIIStringEncoding and NSUTF8StringEncoding, and NSUnicodeStringEncoding. N...

How do I detect a HTTP response, parse the xml and save to a NSString?

I've been trying to figure this out for weeks and i still get nothing. I am using the ASIHTTPRequest and ive successfully sent the data to a server and now I need to get the response XML,parse it and save the elements to each labeled NSString so I can post it to the server. Does anyone have an idea on how to do this? ...

How to determine the order of substrings in an NSString?

Hi, I wanted to know if there is any (easy) method to find the order of a given array of substrings in an NSString? I have a large block of text and a few substrings. I'm only interested in the order that the substrings first appear in the text. So if the text was "can you tell me you are working late if you can" and the substrings w...

Why isn't -stringWithContentsOfURL returning my php echo?

My app accesses a simple php file on my server that does a simple echo "YES"; for testing purposes. I try to get the contents of the echo into an NSString object as below but my string is ALWAYS returning (null). Whats wrong? NSString *theString = [NSString stringWithContentsOfURL:aURLThatEchos]; NSLog(@"Value is: %@", theString); //...

NSString isEqualToString: for \n

I have an Cocoa app that calls a web service. When I parse the response from the web service I am getting a \n as the last character in my foundCharacters delegate for the NSXMLParser for each element in the XML. When I try to do the following: if (![string isEqualToString:@"\n"]) The check will always fails to catch the newline. ...

Objective C: How do I substring an email address in text field to firstpart separated by @

Hi guys, I have been scratching my head trying to find any resources on substringing an email address I get from a textfield into getting the first part before the @ symbol. Ive tried looking at the documentation, playing around with the componentsseparatedbyString. No luck. Thanks for your help in advance ...