User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 456,475 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,770 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 2272 | Replies: 11
Reply
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: reverse the order of words in a sentence

  #11  
Sep 20th, 2008
Sorry I was grouchy.
Reply With Quote  
Join Date: Jun 2006
Location: Blumenau, Brazil
Posts: 71
Reputation: Micheus is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: reverse the order of words in a sentence

  #12  
Sep 30th, 2008
Just another way to do this - introducing recursivity:
  1. function Reverse(var value :string; start :integer) :string;
  2. var
  3. StrTmp :string;
  4. begin
  5. if start <= length(value) then
  6. begin
  7. StrTmp := '';
  8. // getting the word
  9. while (start <= length(value)) and
  10. (value[start] <> ' ') do
  11. begin
  12. StrTmp := StrTmp +value[start];
  13. Inc(start);
  14. end;
  15. // preserve spaces and put it before the word
  16. while value[start] = ' ' do
  17. begin
  18. StrTmp := ' ' +StrTmp;
  19. Inc(start);
  20. end;
  21. // recursive call to get the next word and insert it before the actual - StrTmp
  22. Reverse := Reverse(value, start) +StrTmp;
  23. end else
  24. ReverseWord := '';
  25. end;
  26.  
  27. var
  28. sl :string;
  29. begin
  30. readln(sl);
  31. sl := Reverse(sl, 1);
  32. writeln(sl);
  33. end.
Bye
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)

Brazil - Blumenau
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 2:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC