instring:='one two three, common? let's go! anything'; outstring:='two common let's anything go three one';
Pascal!? I have some string with text, how to shuffle the words in it?
Started by Stasonix, Jun 16 2011 04:27 AM
5 replies to this topic
#1
Posted 16 June 2011 - 04:27 AM
for example:
|
|
|
#2
Posted 16 June 2011 - 02:52 PM
You'll first need to split the words in the string into an array of strings, then select them in a random order.
#3
Posted 17 June 2011 - 01:16 AM
Pascal being an old language with lesser people now actively using and knowing it's syntax, i thought a few links of sample codes would be helpful.
String manipulation functions in Pascal using Borland's turbo pascal compiler.
TURBO PASCAL STRINGS
As mentioned by Winged Panther, create an array of strings using syntax here if you have the above compiler.
Some body wrote a reverse string code in pascal that might help in becoming more familiar with syntax.
String Manipulation - Pascal - Forums at ProgrammersHeaven.com
String manipulation functions in Pascal using Borland's turbo pascal compiler.
TURBO PASCAL STRINGS
As mentioned by Winged Panther, create an array of strings using syntax here if you have the above compiler.
Some body wrote a reverse string code in pascal that might help in becoming more familiar with syntax.
String Manipulation - Pascal - Forums at ProgrammersHeaven.com
#4
Posted 17 June 2011 - 03:10 PM
The other relevant question: is this Turbo Pascal, ObjectPascal, FreePascal, other?
#5
Posted 16 August 2011 - 03:42 PM
fayyazlodhi said:
Pascal being an old language with lesser people now actively using and knowing it's syntax, ...
#6
Posted 23 August 2011 - 06:53 AM
This is my 1st post so, hello to everyone!
It's like WingedPanther said, but i'd use TStringList instead of arrays:
Yep i wrote that in Delphi. Hope there are not many differences.
It's like WingedPanther said, but i'd use TStringList instead of arrays:
function GetToken(Text, SeperateChar: string; Position: Byte): string; var Token: string; Num, Len: Integer; begin Num := 1; Len := Length(Text); while (Num <= Position) and (Len <> 0) do begin Len := Pos(SeperateChar, Text); if (Len <> 0) then begin Token := Copy(Text, 1, Len - 1); Delete(Text, 1, Len); Inc(Num); end else Token := Text; end; Result := Token; end; function RandomizeStr(Text, SeperateChar: string): string; var outString: string; i, TokenRand, TokenCount: integer; TokenList: TStringList; begin TokenCount := Length(Text); TokenCount := TokenCount - Length(StringReplace(Text, SeperateChar, '', [rfReplaceAll, rfIgnoreCase])); Inc(TokenCount); TokenList := TStringList.Create; for i := 1 to TokenCount do TokenList.Add(GetToken(Text, SeperateChar, i)); Randomize; for i := 1 to TokenCount do begin TokenRand := Random(TokenList.Count); outString := outString + SeperateChar + TokenList.Strings[TokenRand]; TokenList.Delete(TokenRand); end; Result := trim(outString); end; // inString := 'one two three, common? let''s go! anything'; // outString := RandomizeStr(inString, ' ');
Yep i wrote that in Delphi. Hope there are not many differences.
Edited by Grim, 23 August 2011 - 07:22 AM.
typos ;(
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









