|
|||
|
Hello all,
I wanted to see if I could use swfkit to replace all carriage return characters "\r" in a text file with the html tag "<BR>". So I edited the notepad.skp (the swfkit notepad src demo) and added this code to the open button to see what happened. trace(s.replace("\r", "<BR>")) The file I opened "test.txt" was simply as follows test 1 2 3 4 the trace returned test<BR>1 2 3 4 I tried replacing the "t"s instead and I got the same thing, it only replaces the first "\r" or "t" it finds and quits. What am I doing wrong or is there another way to do what I am trying to do? Thanks |
|
|||
|
?
put it in a loop that iterates and replaces \r with <BR> until the EOF (end of file)? not sure how you would code it, but it looks like your code is only looking for the first \r and replacing it with <BR> |
|
|||
|
I tried an off hand loop
var re = new RegExp("(\r)","ig"); while(re.test(s) = true) { s.replace("\r","<BR>"); } trace(s); i'm not sure if thats how a loop's done anyway this only caused the trace to freeze. i'll do some more research on loops and give it another try. thanks for the input ![]() |
|
|||
|
;D
YEAH!!! ;DI figured it out! By placing this code in "Open" var vr1 = s.lastIndexOf("<BR>"); while(vr1 >= 0) { r1 = s.replace("<BR>","\r"); s = s.replace() +r1; trace(s); vr1 = s.lastIndexOf("<BR>"); } right before the FlashPlayer.setVariable ("iArea", s); it replaced all the <BR> with \r so when editing it uses the normal \r. Then in "Save" I put this code var vr1 = /\r/gi.test(textArea); while(vr1 == true) { r1 = textArea.replace("\r","<BR>"); textArea = textArea.replace() +r1; trace(textArea); vr1 = /\r/gi.test(textArea); } right before the if (path == null) so when saving it saved it back using the <BR>. It took a while but I got it. Thanks GKFC for the loop tip. I had to use the "s.lastIndexOf("<BR>")" instead of "/\r/gi.test(textArea)" because for some reason unknown to myself it only looped 5 time and quit when using the "/\r/gi.test(textArea)" on on the "Open". Don't know why but it did and I traced it, tried various methods but every time it only did 5 loops and quit. Oh well I got it to work. Thanks again all. |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|