PDA

View Full Version : a simple question...about newlines in txt files


autoplmst6
04-23-2007, 04:38 PM
Hi all:

I have a little doubt, when i use the TextFile.WriteFromString action how i get includes new lines Is possible the use of the \r \n characters for separating lines frenquently used for dialogs message? How i do that?
Thanks in advance

Example:
line one
line two
line three
....

Autoplmst6

Protocol
04-23-2007, 04:44 PM
Yup, dialog messages work in the same way.

Instead of "your message here" which would result in:

your message here

You can type "your\r\nmessage\r\nhere" which would result in:

your
message
here

If you want the quotes, type ' before and after the quotes so typing '"your message here"' would result in:

"your message here"

You can even mix and match by typing 'your "message here"' which would result in a dialog message of:

your "message here"

Have fun!

autoplmst6
04-23-2007, 04:46 PM
Thanks for reply:
I think I explained bad what I was telling is how to write in txt adding newlines ...Sorry for the mistake

Protocol
04-23-2007, 04:54 PM
Ahhhh...still not totally clear, but yes, \r\n works in the TextFile.WriteFromString action. To do so you'd simply place the \r\n inside direct text quotes such as:

"The cow jumped over\r\nthe moon"

Which would result in:

The cow jumped over
the moon

Or if you're dealing with variable string data, then you would simply join the variable name to the \r\n command within quotes so that:

MyVariable1 = "The cow jumped over"
MyVariable2 = "the moon"
MyString = (MyVariable1.."\r\n"..MyVariable2);
TextFile.WriteFromString (_DesktopFolder.."\\MyTextFile.txt", MyString, false);

But if you're starting from scratch (creating a new text document from a blank or preformatted template), I'd recommend the TextFile.WriteFromTable action and create a more specific and easily editable line of code that would create the same effect such as:

MyStringData = "Line Five";
MyTable = {"Line 1", "Line 2", "", "Line 3", "Some other text", "Line 4", MyStringData};
TextFile.WriteFromTable (_DesktopFolder.."\\MyTextFile.txt", MyTable, false);

This would result in a text file on your desktop called "MyTextFile.txt" with the following lines:

Line 1
Line 2

Line 3
Some other text
Line 4
Line Five

Pretty simple, yet powerful schtuff! Tables are much easier to work with when dealing with data in "virtual grids" and can be swapped back and forth with strings just as easily.I hope this helps...

Protocol

yosik
04-23-2007, 04:55 PM
You can also use the double bracket method:
[[
any text you have
written in a specific format
will appear as such
]]

Good luck
Yossi

autoplmst6
04-23-2007, 05:05 PM
Ok, thanks for your kind help :yes to both protocol and yossi

CyberRBT
04-23-2007, 10:14 PM
@ yosik:

Well ... i never knew about the [[ ]] trick. Just tried it. Cool.

Thanks