Re: C++ Strings Handling
Re: C++ Strings Handling
- Subject: Re: C++ Strings Handling
- From: Rosyna <email@hidden>
- Date: Fri, 24 May 2002 11:39:12 -0700
Ack, at 5/24/02, John Haager said:
On Friday, May 24, 2002, at 01:16 AM, Nathan Zamecnik wrote:
If you are refering to just a string of characters then NSString and
NSMutable string should do the trick. But, if you are looking to convert
the STL string class into an NSString then from what I know you would have
to write your own class that takes a C++ string and returns a NSString.
Doesn't have to be a class. A short function would work just as well.
yes, .data() or .c_str()
Basically, just take your C++ string and iterate through it taking each char
member of the string and sending that char to a NSMutableString and then
returning that string. There may be a NSString method that does this that I
don't know of though.
Actually, that would be pretty inefficient. I'm pretty sure C++
strings have a method for obtaining a char * C string. This can
then be fed into NSString's stringWithCString method. Much faster,
and no need for the intermediate Mutable String.
you'd use stringobject.c_str() to get a C style string from a C++
string. The data is not copied so do not release the resulting
string. Also, subsequent calls to non-const strings are most likely
to make the string you received from c_str() invalid. So do not use
c_str() until you are prepared to use the c-string.
NSString* string=[NString stringWithCString:cppstring.c_str()];
.data() returns an array of characters that is not null terminated.
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
---
Please include any previous correspondence in replies, it helps me
remember what we were talking about. Thanks.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.