Skip to main content
October 2, 2010
Answered

Multiline String variable

  • October 2, 2010
  • 1 reply
  • 1049 views

Hello everyone

I need to place a multiline text into a .txt file.

Have a .php service file that creates a file from App's parameters sended to it:

<?php

$getVar = $_POST['TheString'];

$file = 'test.txt';

$writeVar = fopen($file,'w');

fwrite($writeVar,$getVar);

fclose($writeVar);

?>

and the collection of AS service functions to send parameters.

        private function sendData(str:String):void {
            variables = new URLVariables();
            fData = new URLRequest("fileservices/SaveService.php");
            fData.method = URLRequestMethod.POST;
            fData.data = variables;
            fLoader = new URLLoader();
            fLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
            fLoader.addEventListener(Event.COMPLETE, sendComplete);
            variables.TheString = str;
            fLoader.load(fData);
        }

All works, but can only write a single-line string into a file.

when send a string containing '/n' paragraph character, it does not work in .txt file opened with Notepad.

So, what is that specific character to use to mark paragraphs returns,

or should i use the different class instead of String,

or have i to edit my .php file to add such usability (and what is that magic changes to bring)?

Thanks in advance

This topic has been closed for replies.
Correct answer kglad

Sorry, i used forwrahd slash hear, but i used backslash in my code. When opening te resulting text file in Flex's editor, it's multiline!

But when with the other program, it's not!

There's string's procedure

public function composeJobAd(item:Object):String {
            var string:String;
            string = item.Profession;
            string = string+'\r';  //////////////////// or '\n', it doesn't matter
           
            return string;
        }

There's final string procedure:

private function prepareData(dataCollection:Object):void {
            var str:String = '';
            
            for each (var item:Object in dataCollection) {
                var comp:StringComposer = new StringComposer();
                str = str + comp.composeJobAd(item);
            }
            sendData(str);
        }

Thank you Kglad any way!

I surprised, but nobody can tell me what to do.


just about all applications will show two lines when your use \r EXCEPT notepad.  for notepade, use

"\r\n"

for a new line

1 reply

kglad
Community Expert
Community Expert
October 2, 2010

\n for new line

\r for carriage return.

October 2, 2010

those does not work when save to a .txt

that symbols could only be recognized by flash environment, not by Notepad.

I wrote.

kglad
Community Expert
Community Expert
October 2, 2010

you used a forward slash.  use a backslash.

if you don't see multiline text in your text file, show the string you're writing to your text file.