Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: newlines

From: arolls:idatam:au at: 7-Nov-2001 16:12

I reckon you should check for any whitespace characters after your first two lines. Actually, that's not the problem. Try this instead of that useless knee-jerk reaction. s: "^/^/^/^/hello there^/^/^/^/^/" while [p: find s "^/^/^/"][remove p] It removes character by character, if it keeps finding three in a row, instead of replacing three with two and placing the index after the two. -- Explanation -- Pretend N is a newline in the original string, and n is a new newline inserted by our function. Here's the string at the beginning, with the index at the first position: s: "NNNN" ^ Now, after we do [replace s "NNN" "nn"]: s == "nnN" ^ The index is after the inserted replace string! That means a subsequent REPLACE will only see ONE newline character (the final "N"). But we really need to go back to the beginning and see if the two ok-sized bits have joined forces into a over-sized monster. Anyway, the while loop above seems to solve it. Anton.