Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-13-2003, 06:37 AM
Junior Member
 
Join Date: Nov 2003
Posts: 3
Default replace text question

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
Reply With Quote
  #2 (permalink)  
Old 11-14-2003, 02:34 AM
Member
 
Join Date: Sep 2003
Posts: 95
Default Re:replace text question

?

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>
Reply With Quote
  #3 (permalink)  
Old 11-14-2003, 04:44 AM
Junior Member
 
Join Date: Nov 2003
Posts: 3
Default Re:replace text question

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
Reply With Quote
  #4 (permalink)  
Old 11-16-2003, 07:43 AM
Junior Member
 
Join Date: Nov 2003
Posts: 3
Default Re:replace text question

;D YEAH!!! ;D
I 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.
Reply With Quote
  #5 (permalink)  
Old 11-17-2003, 01:06 AM
Member
 
Join Date: Sep 2003
Posts: 95
Default Re:replace text question

;D

nice one.

so my cheque is in the mail then?

Reply With Quote
  #6 (permalink)  
Old 11-17-2003, 12:58 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:replace text question

Hi,

The
Code:
var s = "1\r\n2\r\n3\r\n";
trace(s.replace(/\r\n/gi, "<br>"));
can also work.

The output is: 1<br>2<br>3<br>
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:42 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.