Store text with "Carnage Returns" in a text file? - Solved

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Store text with "Carnage Returns" in a text file? - Solved

Post by DR White »

How do you Store text with "Carnage Returns" in a text file, when it is one of multiple items?

Thanks,

David
Last edited by DR White on Tue Mar 14, 2017 10:13 am, edited 1 time in total.
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store text with "Carnage Returns" in a text file?

Post by Klaus »

Hi David,

I don't have the slightest idea what you are talking about? :shock:


Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Store text with "Carnage Returns" in a text file?

Post by dunbarx »

Hi.

Carnage returns are very unstable; be careful how you use them.

Carriage returns (ASCII 10) though, are pretty straightforward, and require no special handing.

Craig Newman
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store text with "Carnage Returns" in a text file?

Post by Klaus »

Oh, yep, makes sense, as a non-native speaker I thought I was missing something.
Google only pointed me to some "horror clown" musical? WTF? :D
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Store text with "Carnage Returns" in a text file?

Post by dunbarx »

Yep?
You do pretty damn well, Klaus. :wink:

Craig
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Store text with "Carnage Returns" in a text file?

Post by DR White »

Yes, I did not describe my issue very well...

I am putting "Potatoes" into tVeg1
I am putting "Corn" into tVeg2
I am putting "Beans" & cr & "Tomatoes" & cr "Spinach" into tVeg3
I put tVeg1 & tVeg2 & tVeg2 into tSave

--- Saving Data
put tSave into url("file:" & tFile)


---- Retrieve data------
if there is a file tFile then
put url("file:" & tFile) into SetupData
end if

When I get the items one line at a time from SetupData, instead of item 3 of tLine having "Beans" & cr & "Tomatoes" & cr "Spinach", it has just has one item "Beans" and my next tLine of SetupData has just "Tomatoes" instead of three items.

How do I get all 3 things together of item 3 to put them into the same string?

Thanks,

David
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Store text with "Carnage Returns" in a text file?

Post by dunbarx »

Hi.

You are getting back exactly what you put in.

You are missing returns. Step through the portion of your handler that builds the variables. Try adding returns after the lines that load "tVeg1", etc.

Also, when you ask for "items", is that what you meant? Because you might want to ask for "lines". Returns are line delimiters, not item delimiters, unless you make them so.

Craig
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Store text with "Carnage Returns" in a text file?

Post by DR White »

The problem is that I want to save a contact list which includes carriage returns as below:

Name:
John Doe

Phone Number:
1 555 333 4444

Address:
2545 Wood Drive
Roanoke Virginia
24400

How can I save this in a text file?

Thanks

David
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store text with "Carnage Returns" in a text file?

Post by Klaus »

Hi David,

do this:

Code: Select all

...
put "2545 Wood Drive" & CR & "Roanoke Virginia" & CR & "24400" into tAddress
put urlencode(tAddress) into tVeg3
...
Turns multi-linetext into single-line text, you get the picture. :D


Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Store text with "Carnage Returns" in a text file?

Post by dunbarx »

Hmmm.

Are you sure you are comfortable with applying returns to text in general? All the suggestions here have assumed so. Does this make sense to you?

Code: Select all

put "can be applied" into temp
put return & "in different ways?" after temp
put "See how returns" & return before temp
Craig
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Store text with "Carnage Returns" in a text file?

Post by FourthWorld »

You might also consider using an array:

Code: Select all

put "Potatoes" into tA[1]
put "Corn" into tA[2]
pit "Beans"&cr& "Tomatoes" &cr& "Spinach" into tA[3]
put arrayEncode(tA) into url ("binfile:"& tFile)
To read:

Code: Select all

put url ("binfile:" & tFile) into tData
put arrayDecode(tData) into tA
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Store text with "Carnage Returns" in a text file?

Post by DR White »

Klaus, Craig and Richard are Awesome.

Thanks so much for your help and the other great supporters of this forum over the years.

On this task of capturing user entered Returns, I believe that using the url ("binfile:" & tFile) works best for my application.

I strongly recommend LiveCode to everyone and use of this forum

LC is such an incredible programming language with an extremely vast instruction set and so many ways of doing things.

Thanks again to everyone at the LC forum, I could not develop good apps (6 in Google Play Store with 2 that have had 50,000 downloads and 2 in the Apple Store - all my apps are free),

David
Post Reply