2 Replies Latest reply on Sep 18, 2012 8:38 AM by wfzen

    return for text does not display correctly in Notepad

    wfzen Level 1

      I used myString = myString & temp & return to generate text with multiple lines. It displays correctly in MS Word, Write, but they are all packed together in one line when opened with NotePad on Windows.

      What command do I need to add for it to display correctly in NotePad and MS Word, etc word processor programs?


      Same with import with FileIO, text made with Notepad would have any extra return character at the beginning. I need to delete the first character in order for it to display correctly in Director.


      What is the best approach dealing with return key in Director?

       

      Thanks,

        • 1. Re: return for text does not display correctly in Notepad
          James Newton, ACP Level 3

          On Macintosh, new lines are defined by one character: RETURN

          On Unix, new lines are defined by one character, called LineFeed: numToChar(10)

          On Windows, new lines are defined by both characters: RETURN&numToChar(10)

           

          You can use the ReplaceAll() handler below to convert a string in Mac format so that it will appear correctly in NotePad:

           

          myString = ReplaceAll(myString, RETURN, RETURN&numToChar(10))

           

           

          on ReplaceAll(aString, aSubString, aReplacement) ---------------------

            -- INPUT: <aString> is the main string to search in

            --        <aSubString> is a string which may appear in <aString>

            --        <aReplacement> is a string which is to replace all

            --         occurrences of <aSubString> in <aString>

            -- OUTPUT: returns an updated version of <aString> where all

            --         occurrences of <aSubString> have been replaced by

            --         <aReplacement>

            --------------------------------------------------------------------

           

            if aSubString = "" then

              return aString

            end if

           

            tTreatedString = ""

            tLengthAdjust  = the number of chars of aSubString - 1

           

            repeat while TRUE

              tOffset = offset(aSubString, aString)

              if tOffset then

                if tOffset - 1 then

                  put chars(aString, 1, (tOffset - 1)) after tTreatedString

                end if

           

                put aReplacement after tTreatedString

                delete char 1 to (tOffset + tLengthAdjust) of aString

           

              else -- there are no more occurrences

                put aString after tTreatedString

                return tTreatedString

              end if

           

            end repeat

          end ReplaceAll

           

           

          When you read the string back in from the hard disk, you can use this handler to convert a string in any format to a string in Mac/Director format:

           

           

          myDirectorCompatibleString = NormalizeText(myStringInUnknownFormat)

           

           

          on NormalizeText(aString) --------------------------------------------

            -- INPUT: <aString> should be a string

            -- ACTION: Removes DOS or UNIX line endings and replaces them with

            --         MAC line endings

            -- OUTPUT: Returns a string with no LF characters

            --------------------------------------------------------------------

           

            if not stringP(aString) then

              return ""

            end if

           

            vLF   = numToChar(10)

            vCRLF = RETURN&vLF

            if aString contains vLF then

              if aString contains vCRLF then

                aString = ReplaceAll(aString, vCRLF, RETURN)

           

              else

                aString = ReplaceAll(aString, vLF, RETURN)

              end if

            end if

           

            return aString

          end NormalizeText

          • 2. Re: return for text does not display correctly in Notepad
            wfzen Level 1

            James, thanks a lot for you help. The function does exactly what I need.