Monday, March 22, 2010

writereturn or workaround?

Googling, trying to find some usefull info how to use
writereturn()

I have a textmember with some text, opening the saved file
looks wrong in notepad. No new lines.

Now I simply write the file like this:

writeString(fileObj,member(''mytext'').text)



all lingo

cheerswritereturn or workaround?
%26gt; Googling, trying to find some usefull info how to use
writereturn()



If you execute the following from your message window:

put interface(xtra ''FileIO'')

one of the output lines is:

writeReturn object me, symbol platform -- Inserts #unix,
#macintosh or

#windows platform line return.



However, using this method relies on you writing out your
text line by

line rather than as an entire ''lump''



You could use a regular expression via JavaScript or the
PRegEx xtra to

replace RETURN characters with CRLF. One advantage of the
(free) PRegEx

xtra is that it will also write to disk with a single line of
code.

Here's a little handler that might help (requires PRegEx

%26lt;
http://www.openxtras.org%26gt;):

--

on mWriteDOSString aString, aPath

l = [aString]

nFound = re_replace(l, ''(\x0D)(?!\x0A)'', ''g'', ''\x0D\x0A'')

if nFound %26lt; 0 then alert(''Error:'' %26amp;%26amp;
PRegEx_DescribeError())

nWritten = re_write(aPath, l)

if nWritten %26lt; 0 then alert(''Error:'' %26amp;%26amp;
PRegEx_DescribeError())

end

writereturn or workaround?
Thanks for your help Sean


http://www.mediamacros.com/item/item-950637601/
just found this little snippet which worked
%26gt;
http://www.mediamacros.com/item/item-950637601/
just found this little snippet which worked



By the look of it, the script you referred to reads in a
DOS-formatted

string and removes the LF character so that you can display
the results

in a #text/#field sprite - essentially translating CRLF into
CR. Here's

a handler that uses PRegEx to do the same:

--

on mReadDOSString aPath

tList = re_read(aPath)

if ilk(tList, #list) = 0 then

-- error

alert(''Error reading file:'' %26amp;%26amp;
PRegEx_DescribeError())

exit

end if

nReplaced = re_replace(tList, ''(\x0D\x0A)'', ''g'', ''\x0D'')

if nReplaced %26lt; 0 then alert(''Error in translation:''
%26amp;%26amp;

PRegEx_DescribeError())

return tList[1]

end

No comments:

Post a Comment