NSString, scramble
NSString, scramble
- Subject: NSString, scramble
- From: "Michel M.J. Haver" <email@hidden>
- Date: Sun, 01 Jul 2001 14:38:25 +0200
Hello,
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.
I want to read a couple of string and then scramble the strings by mixing
the characters in the strings to new ad random positions.
Problem Description by Example
I want to convert a string like for example "heart" to "retah"
or the next time you run the program the example string "heart" will be
converted in an other random scramble string like "tarhe".
In Pascal scrambling a string looks something it looks something like this:
function ScrambleTheString (scramblestring: string): string;
var
deletestr, scramblestr: string[24];
scrambleteken: string[1];
position, n, stringlengte, scramblenr: integer;
begin
EraseString(scramblestr);
EraseString(scrambleteken);
stringlengte := length(scramblestring);
deletestr := scramblestring;
for n := 1 to stringlengte do
begin
scramblenr := Randomize(stringlengte);
scrambleteken[1] := deletestr[scramblenr];
position := Pos(scrambleteken[1], deletestr);
{Verhaspelen van de letters in de string.}
Delete(deletestr, position, 1);
scramblestr := Concat(scramblestr, scrambleteken[1]);
stringlengte := Length(deletestr);
end;
ScrambleTheString := scramblestr;
end;
How I can implement such a random string scramble functionality with the
cocoa objects NSString, NSMutableString is something of a riddle to me which
I am working to find out.
Does someone has some tips for solving this riddle?
I prefer to do it in Cocoa or is it should this kind of string manipulation
be done in C or C++?
Cheers,
Michel