Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 14, 2005, 10:54 AM   #1
JimmyFeatures
macrumors newbie
 
Join Date: Oct 2005
Character arrays in Xcode

I want to assign the value of a text field to a character array in Xcode. How would I go about doing this?

Thanks.
JimmyFeatures is offline   0 Reply With Quote
Old Nov 14, 2005, 11:03 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by JimmyFeatures
I want to assign the value of a text field to a character array in Xcode. How would I go about doing this?

Thanks.
What languge are you using? XCode supports Obj-C, C++, Java, AppleScript and probably lots more! Also what type is the character array? Is it char (i.e. a byte) or unichar (2 bytes I think).
robbieduncan is offline   0 Reply With Quote
Old Nov 14, 2005, 11:10 AM   #3
JimmyFeatures
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
Basically, I want to assign

char array[255]

to a text input.
JimmyFeatures is offline   0 Reply With Quote
Old Nov 14, 2005, 11:18 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by JimmyFeatures
Basically, I want to assign

char array[255]

to a text input.
You still havn't said what language! That narrows it to C++ (Carbon) or Obj-C (Cocoa). When you say text input do you mean from the command line or from a text box on screen (in a window)? If it's from a text box in a window you need to very carefull with this as the string value from that text box will be 16-bit Unicode, whereas your array is for 8-bit chars.

You can do do this in Cocoa with something like:
Code:
IBOutlet NSTextView *textView;  // Conect in IB

...

char *array = [[textView stringValue] UTF8String];
This assumes that the text in the text box is a UTF-8 string (i.e. ASCII). The array returned will be null terminated, not 255 bytes long.
robbieduncan is offline   0 Reply With Quote
Old Nov 14, 2005, 11:24 AM   #5
JimmyFeatures
Thread Starter
macrumors newbie
 
Join Date: Oct 2005
OK. To clear this up.

I am using OBJ-C in cocoa, and would like to assign a text input, which is a text box inside a window (not command line) to a C/C++ style character array.
JimmyFeatures is offline   0 Reply With Quote
Old Nov 14, 2005, 11:28 AM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by JimmyFeatures
OK. To clear this up.

I am using OBJ-C in cocoa, and would like to assign a text input, which is a text box inside a window (not command line) to a C/C++ style character array.
Then the above will work for UTF-8 strings. If you need it in an array that you have assigned you can just copy the characters across or use the provided NSString method. You need to know what encoding you are in.

Perhaps you could read the documentation.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
adding NSNumbers in xcode ghousemd iPhone/iPad Programming 2 Aug 26, 2011 05:56 AM
changing Base SDK in xcode started giving errors hrishidev Mac Programming 4 Apr 21, 2011 01:29 AM
Question about reading into a character array (C) mac2x Mac Programming 4 Nov 6, 2010 11:40 AM
Hide linefeed and tab characters in xcode editor blomma Mac Programming 9 Jun 16, 2010 06:28 PM
Do Char Arrays Work The Same in Xcode as they do in Visual Studio? bobber205 Mac Programming 21 Feb 19, 2007 07:23 PM


All times are GMT -5. The time now is 09:03 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC