Re: NSString, scramble
Re: NSString, scramble
- Subject: Re: NSString, scramble
- From: David Remahl <email@hidden>
- Date: Sun, 1 Jul 2001 15:26:59 +0200
Hello,
Hi!
I try to get my feet wet by starting to port an Pascal application I
wrote
some years ago to cocoa. I have problems to find the correct statements
in
NSString, NSMutableString for something I can easily do in Pascal.
Everything is simple if you know how to do it. Well although I loved the
cleanness of cocoa programming, translating my ideas in cocoa speak
isn't
natural to me at this moment in time. So I am asking for a little help
of
the experienced cocoa programmer.
Even though my knowledge in both Dutch and Pascal are fairly limited, I
had a go...This is what I came up with. I wrote it using the cocoa
classes, since you asked for it. However, pure C would also be a good
option if speed is an option rather than clarity.
NSMutableString* tempString = [NSMutableString
stringWithString:@"heart"];
NSMutableString* outString = [NSMutableString string];
int randpos = 0;
int currentLength;
NSRange oneCharRange;
srand(time(0));
currentLength = [tempString length];
while( currentLength )
{
oneCharRange = NSMakeRange(rand() % currentLength,1);
[outString appendString:[tempString
substringWithRange:oneCharRange]];
[tempString deleteCharactersInRange:oneCharRange];
currentLength--;
}
NSLog(@"In: %@ Out: %@",inString,outString);
/ Regards, David