Page 1 of 4

Remove Carriage Returns

Posted: Thu Mar 31, 2016 8:55 am
by bbhank
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:

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 10:44 am
by Dixie
try something like...

Code: Select all

replace return with empty in fld "xyz"

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 1:13 pm
by bbhank
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?

:(

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 2:22 pm
by Dixie
Oh, so you are using a datagrid are you !?... You didn't make that clear... look up 'replace' in the dictionary'

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 2:33 pm
by bbhank
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.

:(

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 4:53 pm
by jacque
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 5:04 pm
by SparkOut
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 5:12 pm
by bbhank
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"

:(

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 5:39 pm
by bbhank
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:15 pm
by Klaus
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?

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:29 pm
by bbhank
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:34 pm
by Klaus
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:36 pm
by bbhank
DataGrid is form.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:39 pm
by bbhank
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.

Re: Remove Carriage Returns

Posted: Thu Mar 31, 2016 6:55 pm
by Klaus
Sure it did!

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