 |
 |
Cocoa NSString question
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2003
Status:
Offline
|
|
I am trying to do something with the Adium source, and came across this problem, that I cannot figure out. How can I typecast the ASCII code for a character in to a string (or character, or even a character array)? In C++, I could typecast it as (char)ASCII_Number, but in Objective-C, it doesn't seem to be doing it the same way.
To elaborate on what I am doing, I am trying to get Adium to recognize what a tab is, and I have tried both typecasting, and saying "\t" and '\t' and non if it works.
(Last edited by KraziKid; Jul 27, 2004 at 09:32 PM.
)
|
|
15 inch MacBook Pro 2.16 GHz, 2 GB RAM, 7200 RPM 100GB HDD.
Dual 2.5 GHz Power Mac G5, 1 GB RAM, 250 GB HDD, ATI Radeon X800XT.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Check the NSString method "stringWithCharacters:". Does this do what you require?
Otherwise, you should be able to type cast to a C string in the same way as in C (because Objective-C is merely an extension to C), and then use the NSString methos "stringWithCString:".
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2003
Status:
Offline
|
|
Originally posted by Brass:
Check the NSString method "stringWithCharacters:". Does this do what you require?
Otherwise, you should be able to type cast to a C string in the same way as in C (because Objective-C is merely an extension to C), and then use the NSString methos "stringWithCString:".
Thanks for that help. Right now, I have this code:
unichar chr[2];
chr[0]=011;
chr[1]=nil;
NSString *tabChar=[NSString stringWithCharacters:&chr length:1];
Is there any way to consolidate that in to one line? This does what I want, but I would prefer if I could get it down in to one line.
|
|
15 inch MacBook Pro 2.16 GHz, 2 GB RAM, 7200 RPM 100GB HDD.
Dual 2.5 GHz Power Mac G5, 1 GB RAM, 250 GB HDD, ATI Radeon X800XT.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Apr 2001
Location: Seattle, WA
Status:
Offline
|
|
why not do this?
Code:
NSString *tab = @"\t";
|
|
The short shall inherit the earth. Just you wait. You won't see us coming. We'll pop out from under tables, beds, and closets in hordes. So you're tall, huh? You won't be so tall when I chew off your ankles. Mofo
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2003
Status:
Offline
|
|
Originally posted by cheerios:
why not do this?
Code:
NSString *tab = @"\t";
I have tried that, and it does not do what I require. I have no idea why, but it just does not.
|
|
15 inch MacBook Pro 2.16 GHz, 2 GB RAM, 7200 RPM 100GB HDD.
Dual 2.5 GHz Power Mac G5, 1 GB RAM, 250 GB HDD, ATI Radeon X800XT.
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally posted by KraziKid:
Thanks for that help. Right now, I have this code:
unichar chr[2];
chr[0]=011;
chr[1]=nil;
NSString *tabChar=[NSString stringWithCharacters:&chr length:1];
Is there any way to consolidate that in to one line? This does what I want, but I would prefer if I could get it down in to one line.
Here's how I make an NSString from a unicode fraction character (all in one line):
NSString *threeQuarters = [NSString stringWithCharacters:(unichar *)"\x00\xbe" length:1];
However, if you're using plain ASCII characters, it's probably easier to simply do this:
NSString *theString = [NSString stringWithCString:"blahblahblah"];
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Dec 2003
Status:
Offline
|
|
Well, thanks for all the help. I ended up doing this in one line using this:
[NSString stringWithCString:"\t"]
For some reason, originally \t wasn't working, but when I did it using that method, it seemed to work now.
|
|
15 inch MacBook Pro 2.16 GHz, 2 GB RAM, 7200 RPM 100GB HDD.
Dual 2.5 GHz Power Mac G5, 1 GB RAM, 250 GB HDD, ATI Radeon X800XT.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|