Remove Carriage Returns

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: Klaus, FourthWorld, heatherlaine, kevinmiller

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 8:55 am

I have a description field that is called from a MySQL database. It has carriage returns and/or line feeds that cause parts of the text to go to Description field in a new row it creates, then into the next row, and the next row, until all the returns in the field are used. The problem is how to keep the whole contents in one field so that the returns don't cause it to go to the next Description field.
Looked far and wide but found nothing that worked.

:cry:
Last edited by bbhank on Thu Mar 31, 2016 2:39 pm, edited 1 time in total.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Remove Carriage Returns

Post by Dixie » Thu Mar 31, 2016 10:44 am

try something like...

Code: Select all

replace return with empty in fld "xyz"

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 1:13 pm

This does go in the Row Behavior, right?
If so, it doesn't work.
Also tried in field script and changing fld to field in each.
Doesn't work there either.
Suggestions?

:(

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Remove Carriage Returns

Post by Dixie » Thu Mar 31, 2016 2:22 pm

Oh, so you are using a datagrid are you !?... You didn't make that clear... look up 'replace' in the dictionary'

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 2:33 pm

Found this: replaceText(stringToChange, matchExpression, replacementString) from Dictionary.
then
replaceText("Description","cr"," ") looks like it should work.

Does not work. Not enough information. The field is Description.

I want to either remove or change carriage returns so that they do not cause the text to flow into the next Description field.

:(

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5084
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Remove Carriage Returns

Post by jacque » Thu Mar 31, 2016 4:53 pm

ReplaceText is used for regular expressions, which is probably overkill for what you're doing. "Replace" is all you need.

One reason your replaceText function didn't work is because you quoted "cr", which is a constant and should not have quotes. By using quotation marks you're making it a literal string, which will only match the exact two characters "cr". Another reason is that replaceText is a function, so if you called it like a command it will fail (it isn't clear if you did that.) Finally, "description" isn't a full object reference, so replaceText will use it as the literal string to search.

Bernd's original suggestions should work as written.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2015
Joined: Sun Sep 23, 2007 4:58 pm

Re: Remove Carriage Returns

Post by SparkOut » Thu Mar 31, 2016 5:04 pm

I think the intrinsic problem is that the records retrieved from the query are cr delimited rows, but each row contains a column with multiple return characters.

Try fetching the data with a query that changes the default record separator, to something you can be sure is not in the dB.
Then replace cr with empty in theFetchedData. Next replace "myFunkySeparator" with cr in theFetchedData.
Maybe then you can apply theFetchedData to the datagrid and have it show properly.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 5:12 pm

Tried these but still no go:

replace cr with " " in field "Description"
replace return with empty in fld "Description"

Used with and without "of me"

:(

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 5:39 pm

This is all in one field. Checked using MS Word to see which caused the problem and found that both line feeds and returns, here, cause this. Also that the tried the methods above to remove them but that so far none have worked. How could this be achieved with a query if these are in one field only? I've looked for this also.

Klaus
Posts: 11110
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Remove Carriage Returns

Post by Klaus » Thu Mar 31, 2016 6:15 pm

How do you fetch the data from the database?
Please show us your Livecode and SQL commands.

Is your datagrid of type TABLE of FORM?

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 6:29 pm

put "SELECT event_state, other_field1, other_field2, other_field3, event_desc FROM wp_my_database WHERE event_state='"& gState &"' ORDER BY event_begin ASC " into tSQL
The state - gState - comes from pull down menu.
DataGrid is form.
Last edited by bbhank on Thu Mar 31, 2016 6:35 pm, edited 1 time in total.

Klaus
Posts: 11110
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Remove Carriage Returns

Post by Klaus » Thu Mar 31, 2016 6:34 pm

bbhank wrote:put "SELECT other_field, other_field1, other_field2, other_field3, event_desc FROM wp_my_database WHERE event_state='"& gState &"' ORDER BY event_begin ASC " into tSQL
OK, that is the SQL command. What about the LC command you are using the SQL in?
bbhank wrote:The state comes from pull down menu.
Aha? :D

Please answer my other question.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 6:36 pm

DataGrid is form.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 6:39 pm

When I took out the linefeeds and carriage returns in Word and pasted that back into the original field in the database, it became "normal" when displayed in LiveCode.

Klaus
Posts: 11110
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Remove Carriage Returns

Post by Klaus » Thu Mar 31, 2016 6:55 pm

Sure it did!

Still waiting for my last question to be answered, so much for "Succinct answers...". 8)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”