Long story shorter...I'm writing some test routines where I want to compare an expected good outcome with a live result. I also want to be able to seed the test cases with known values...which means I'm trying to type @#$%$% escape sequences into the 4D method editor. Do I find this hard? Yes, yes I do. I don't know why, I don't have much trouble in other languages...but with 4D, the \ sequences trip me up regularly.
Anyway. It took me an unexpectedly long time to work out code to do the following: * Take some text. * Escape it. * Brace it in quotes so that it's ready to paste into the method editor. Well, only the second step was hard ;-) This may be old news to many, but I've listed the code below for anyone that ends up wanting it. (I tried the archives and KB but didn't come up with something matching this problem.) Some notes: * I escaped the escape sequences defined here: // http://doc.4d.com/4Dv15R5/4D/15-R5/Writing-a-method.300-2964291.en.html * I wrote some test cases for this code and they worked interpreted and compiled. Yeah! But I'm also the guy trying to automate something that is weirdly hard for me in 4D. So, bug reports gratefully accepted. * There's probably a better way. I'm all ears. And now the code, error management, naming conventions, etc. left to your discretion: $escaped:="" If (Count parameters>=1)// If this isn't true, you should deal with it. $escaped:=$1 $escaped:=Replace string($escaped;"\\";"\\\\";*) $escaped:=Replace string($escaped;"\n";"\\n";*) $escaped:=Replace string($escaped;"\r";"\\r";*) $escaped:=Replace string($escaped;"\t";"\\t";*) $escaped:=Replace string($escaped;"\"";"\\\"";*) $escaped:=Char(Double quote)+$escaped+Char(Double quote) End if $0:=$escaped ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

