Re: Newbie Question about Converting From NSTextField to NSData
Re: Newbie Question about Converting From NSTextField to NSData
- Subject: Re: Newbie Question about Converting From NSTextField to NSData
- From: Ondra Cada <email@hidden>
- Date: Thu, 18 Jul 2002 17:21:10 +0200
On Thursday, July 18, 2002, at 04:42 , Tom Gray wrote:
As always, thanks in advance and sorry about such a bone headed newbie
question. I am reading an NSTextField and want to convert the string value
into an NSData type. I am doing this:
// Read the data from the text field.
theNSString = [[NSSTring alloc] initWithString:[myTextField stringValue]]
;
// Get the length of the string.
length = [theNSString length];
// Convert the NSString to a C String.
theCString = [theNSSTring cString];
// Convert the C string to an NSData.
theNSData = [[[NSData alloc] initWithBytes:theCString length:length]
autorelease];
I know their is a better way.
Right, there is indeed:
theData=[[textField stringValue] dataUsingEncoding:XXX];
where XXX is the string encoding you prefer to use in the data.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.