Re: What's the difference between a C++ and ObjC String?
Re: What's the difference between a C++ and ObjC String?
- Subject: Re: What's the difference between a C++ and ObjC String?
- From: "Frederick C. Lee" <email@hidden>
- Date: Sat, 2 Jul 2005 08:00:57 -0700
Thanks for the info.
I'm quite familiar with the 'front-end' of NSString and the C-string
architecture.
I'm trying to 'glue' some C++ routines within Objective-C with the
premise that there's a huge C++ world out there that I could to tap
from within Objective-C (aka "Objective-C++") rather than re-write
the entire logic.
And on a side note, I'll toy with meshing C++ containers (Vector/List
templates) with Objective-C containers: to see if I can effectively
glean data from the C++ side.
Ric.
On Jul 1, 2005, at 5:49 PM, Todd Blanchard wrote:
There are C "strings" which are just arrays of char terminated with
zero. They look like:
"This is a string"
char* s = 0;
const char *t = "Hi there";
char a[] = "an array of char just big enough to hold this text plus
a null terminator";
char b[256] = "an array of 256 with extras set to zeros";
C++ has resorted to a number of string classes - the most modern of
which is the std::string class found in the STL. You can generally
ignore this as it's cack and useless in the Cocoa environment.
Cocoa uses instances of NSString*. Cocoa strings look like this:
NSString* @"An NSString literal"
NSString* fromCString = [NSString stringWithUTF8String: "A C string
for initialization"];
NSString* fromNSString = [NSString stringWithString: @"Another
NSString literal"];
NSString* formattedString = [NSString stringWithFormat: @"This is
how you do sprintf type things %d %@\n",50,someObject];
etc. You want to use NSString wherever possible in cocoa programming.
NSStrings are immutable - you cannot change them. If you want a
modifyable string, create the subclass NSMutableString instead.
This is in sharp contrast to std::string which is mutable vs const
std::string which is not.
Welcome to the varsity. Shout if you need more help.
On Jul 1, 2005, at 4:12 PM, Frederick C. Lee wrote:
I read that C strings are null terminated whereas C++ strings are
not.
Which leads me to ask, is there any difference between C++ and
ObjC strings?
Ric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden