uping which must be preserved.
The old "reversing a string" problem has long since passed its prime,
and is overdue for retirement. It doesn't really have any practical
purpose, at least not as applied to real natural-language strings, and
it certainly isn't compatible wi
ituations where this will still fail. But it covers most of the
tricky bits, and at least will always produce valid unicode output.
Reversing a string only really makes sense for certain languages
anyhow. Perhaps even just English. The rendering of reversed strings
may also get a bit weir
On Wed, Dec 31, 2008 at 11:29 AM, Dave DeLong wrote:
> Ironic... This question came up in a job interview I had a couple weeks ago.
> The following NSString category will work to reverse a string, and in my
> limited tests, it works with accents, mathematical symbols, and Korean
> characters:
>
>
Looks like the attachment didn't come along. It's up here:
http://davedelong.com/stuff/stringreverse.png
Dave
On Dec 31, 2008, at 9:29 AM, Dave DeLong wrote:
Ironic... This question came up in a job interview I had a couple
weeks ago. The following NSString category will work to reverse a
Ironic... This question came up in a job interview I had a couple
weeks ago. The following NSString category will work to reverse a
string, and in my limited tests, it works with accents, mathematical
symbols, and Korean characters:
- (NSString *) stringByReversingSelf {
NSMutableS
On Wed, Dec 31, 2008 at 4:28 AM, Peter Hudson wrote:
> I have been using the following for a while across a number of languages
> without problems.
>
>
> NSString *s = @"Hello";
> unsigned int length = [s length];
> unsigned int index = length - 1;
>
> NSMutableArray *ma = [NSMutableArray array
I have been using the following for a while across a number of
languages without problems.
NSString *s = @"Hello";
unsigned int length = [s length];
unsigned int index = length - 1;
NSMutableArray *ma = [NSMutableArray array];
while( index < UINT_MAX )
{
NSRange rn
Unfortunately, this is not correct; -[NSString characterAtIndex:]
returns a unichar, which is not a char. In addition, it will give
odd results for composed characters. Depending on what you want,
you might be able to use rangeOfComposedCharacterAtIndex:.
I'd also use NSMutableString inst
On 31/12/2008, at 5:26 PM, Nick Zitzmann wrote:
On Dec 30, 2008, at 10:23 PM, Ron Fleckner wrote:
- (NSString *)reverseString:(NSString *)aString
{
// Do the reversing with the help of an array of chars
int i, j;
const int stringLength = [aString length];
On Wed, Dec 31, 2008 at 12:08 AM, Gabe Shahbazian wrote:
> What is the best way to take an NSString and reverse the characters so that
> "hello" becomes "olleh"?
This doesn't make sense for all locales. Are you sure you want to do this?
--Kyle Sluder
On Dec 30, 2008, at 10:23 PM, Ron Fleckner wrote:
- (NSString *)reverseString:(NSString *)aString
{
// Do the reversing with the help of an array of chars
int i, j;
const int stringLength = [aString length];
char reverseChars[stringLength];
for (
In general, it would perhaps be best to create a c string from the
NSString using the proper text encoding and then iterating through the
C string in reverse, appending each character to an NSMutableString.
Iterating through each character of an NSString is likely to be slow
and the usage
On Dec 31, 2008, at 4:42 PM, Graham Cox wrote:
On 31 Dec 2008, at 4:35 pm, Graham Cox wrote:
I don't think this is legal
Hmm, seems C99 allows this. I didn't know that - my bad.
Personally, I avoid variable length arrays out of fear that the
allocation might fail. On 10.3 or 10.4 I ran
On 31/12/2008, at 4:42 PM, Graham Cox wrote:
On 31 Dec 2008, at 4:35 pm, Graham Cox wrote:
I don't think this is legal
Hmm, seems C99 allows this. I didn't know that - my bad.
--Graham
Ha ha, yes. I resisted trying to explain that because I wouldn't be
able to do it properly. I did
On Dec 31, 2008, at 4:23 PM, Ron Fleckner wrote:
const int stringLength = [aString length];
char reverseChars[stringLength];
for (i = stringLength - 1, j = 0; i >= 0; i--, j++)
{
char c = [aString characterAtIndex:i];
reverseChars[j
On 31 Dec 2008, at 4:35 pm, Graham Cox wrote:
I don't think this is legal
Hmm, seems C99 allows this. I didn't know that - my bad.
--Graham
___
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator c
On 31 Dec 2008, at 4:23 pm, Ron Fleckner wrote:
char reverseChars[stringLength];
Have you tested this? I don't think this is legal - you can't declare
a statically sized array with a dynamically computed size. The
compiler might let it through because stringLength is declared const,
ev
On 31/12/2008, at 4:08 PM, Gabe Shahbazian wrote:
What is the best way to take an NSString and reverse the characters
so that
"hello" becomes "olleh"?
Thanks for any and all help,
Gabe S
Hi Gabe.
I don't think there's anything in Cocoa that does this for you. I
needed to reverse strings
What is the best way to take an NSString and reverse the characters so that
"hello" becomes "olleh"?
Thanks for any and all help,
Gabe S
___
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to th
19 matches
Mail list logo