Advertisement
yazdmich

Junk Food

Oct 26th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. % Go to http://pastebin.com/bVTNL6Np to obtain the text for junkfood.txt, save in the same folder as you are running Turing in. Turing will make junkfoodfixed.txt % and junkfoodfixed2.txt by itself
  2.  
  3. var line1, line2, before, after : string
  4. var StreamNum1, StreamNum2, junkfound1, junkfound2, space2, space3, space4 : int
  5.  
  6. open : StreamNum1, "junkfood.txt", get
  7.  
  8. if StreamNum1 < 0 then
  9. put "File Access error: 404 or file not readable"
  10. else
  11. open : StreamNum2, "junkfoodfixed.txt", put
  12. loop
  13. exit when eof (StreamNum1)
  14. get : StreamNum1, line1 : *
  15. junkfound1 := index (line1, "Junk Food")
  16. junkfound2 := index (line1, "junk food")
  17. if junkfound1 > 0 then
  18. before := line1 (1 .. junkfound1 - 1)
  19. line2 := "Unhealthy Treats"
  20. after := line1 (junkfound1 + 9 .. *)
  21. line1 := before + line2 + after
  22. elsif junkfound2 > 0 then
  23. before := line1 (1 .. junkfound2 - 1)
  24. line2 := "unhealthy treats"
  25. after := line1 (junkfound2 + 9 .. *)
  26. line1 := before + line2 + after
  27. end if
  28. put : StreamNum2, line1
  29. end loop
  30. close : StreamNum1
  31. close : StreamNum2
  32. end if
  33.  
  34. open : StreamNum1, "junkfoodfixed.txt", get
  35.  
  36. if StreamNum1 < 0 then
  37. put "File Access error: 404 or file not readable"
  38. else
  39. open : StreamNum2, "junkfoodfixed2.txt", put
  40. loop
  41. exit when eof (StreamNum1)
  42. get : StreamNum1, line1 : *
  43. space4 := index (line1, " ")
  44. space3 := index (line1, " ")
  45. space2 := index (line1, " ")
  46. if space4 > 0 then
  47. before := line1 (1 .. space4)
  48. after := line1 (space4 + 3 .. *)
  49. line1 := before + after
  50. end if
  51. if space3 > 0 then
  52. before := line1 (1 .. space3)
  53. after := line1 (space3 + 2 .. *)
  54. line1 := before + after
  55. end if
  56. if space2 > 0 then
  57. before := line1 (1 .. space2)
  58. after := line1 (space2 + 1 .. *)
  59. line1 := before + after
  60. end if
  61. put line1
  62. put : StreamNum2, line1
  63. end loop
  64. close : StreamNum1
  65. close : StreamNum2
  66. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement