2 Replies - 12188 Views - Last Post: 21 April 2011 - 05:29 PM

#1 sidebrok  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 61
  • Joined: 28-October 10

convert char/string to NSString?

Posted 21 March 2011 - 01:17 PM

Does anyone know how i can convert A char or string to a NSString?
I tried something like this, but it didnt work:(

NSString *myString;
char myCharString[10] = "mystring";
myString = myCharString;


and
int x;
NSString *myString;
char myCharString[10] = "mystring";
while (myCharString[x] != "\0") {
myString = myCharString[x];
x++;
}


but it didnt work.

Is This A Good Question/Topic? 0
  • +

Replies To: convert char/string to NSString?

#2 GWatt  Icon User is online

  • member icon

Reputation: 276
  • View blog
  • Posts: 3,075
  • Joined: 01-December 05

Re: convert char/string to NSString?

Posted 21 March 2011 - 04:40 PM

View Postsidebrok, on 21 March 2011 - 04:17 PM, said:

Does anyone know how i can convert A char or string to a NSString?
I tried something like this, but it didnt work:(

NSString *myString;
char myCharString[10] = "mystring";
myString = myCharString;


and
int x;
NSString *myString;
char myCharString[10] = "mystring";
while (myCharString[x] != "\0") {
myString = myCharString[x];
x++;
}


but it didnt work.


There are a few selectors to already do this. You should look at the NSString documentation.
Was This Post Helpful? 0
  • +
  • -

#3 Robb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 58
  • Joined: 16-October 06

Re: convert char/string to NSString?

Posted 21 April 2011 - 05:29 PM

You need to initialise an NSString with an UTF8String.

	char myCharString[10] = "mystring";
	NSString *myString = [[NSString alloc] initWithUTF8String:myCharString];


There is a ton of documentation on things like this. You should check it first, what you need will usually be in there.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1