Using expressions with "<" and ">"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Using expressions with "<" and ">"
Does anyone know how to force LiveCode to return a string instead of calculating the result when using "<" and ">" and "</" ?
With the PUT command there is no problem, but I need it with ANSWER or RETURN to deliver a result within a routine.
For example:
answer "<" & aaa & ">" & 555 & "</" & aaa & ">"
returns 555, but I want it to return:
<aaa>555</aaa>
Thank you very much.
With the PUT command there is no problem, but I need it with ANSWER or RETURN to deliver a result within a routine.
For example:
answer "<" & aaa & ">" & 555 & "</" & aaa & ">"
returns 555, but I want it to return:
<aaa>555</aaa>
Thank you very much.
Re: Using expressions with "<" and ">"
Hola Fermin,
I'm afraid you can't!
Because this is a "feature" of the answer dialog, if a string starts with < and ends with >
LC will see this as HTML tags and if LC does not know the actual tag(s), it only supports a
very basic set of HTML tags, it will just neglect them.
You could do:
1. Report an enhancement request so we can switch this behavior (interpreting as HTML) on and off
and/or
2. Create your own custom dialog -> a little modal stack with a "OK" button to close the stack.
Best
Klaus
I'm afraid you can't!
Because this is a "feature" of the answer dialog, if a string starts with < and ends with >
LC will see this as HTML tags and if LC does not know the actual tag(s), it only supports a
very basic set of HTML tags, it will just neglect them.
You could do:
1. Report an enhancement request so we can switch this behavior (interpreting as HTML) on and off
and/or
2. Create your own custom dialog -> a little modal stack with a "OK" button to close the stack.
Best
Klaus
Re: Using expressions with "<" and ">"
Hi Fermin,
if you just want to check the syntax you could put it into the message box:
(&& the long time added to make sure it is a current message in the message box)
or into a separate field for development
Kind regards
Bernd
if you just want to check the syntax you could put it into the message box:
Code: Select all
put "<" & "aaa" & ">" & "555" & "</" & "aaa" & ">" && the long time
or into a separate field for development
Code: Select all
put "<" & "aaa" & ">" & "555" & "</" & "aaa" & ">" into field "myField"
Bernd
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: Using expressions with "<" and ">"
Fake It!
-
-
- Attachments
-
- FAKE IT.livecode.zip
- Stack.
- (1.07 KiB) Downloaded 207 times
Re: Using expressions with "<" and ">"
Thank you for your answers. I understand the problem now and will try to find another way to fix it.
As a curiosity:
I presented the problem to ChatGPT and it's clear that it doesn't have any complexes. It may not have any idea what it's saying, but at least it says it with a lot of confidence.
Although none of them are useful, here are some of the proposals it has made:
answer quote & "<" & aaa & ">" & 555 & "</" & aaa & ">" & quote
--
answer quote("<" & aaa & ">" & 555 & "</" & aaa & ">")
--
answer "\<" & aaa & "\>" & 555 & "\</" & aaa & "\>"
--
put "<aaa>" & 555 & "</aaa>" into myString
put replaceText(myString, "<", "<") into myString
put replaceText(myString, ">", ">") into myString
answer myString
--
As a curiosity:
I presented the problem to ChatGPT and it's clear that it doesn't have any complexes. It may not have any idea what it's saying, but at least it says it with a lot of confidence.

Although none of them are useful, here are some of the proposals it has made:
answer quote & "<" & aaa & ">" & 555 & "</" & aaa & ">" & quote
--
answer quote("<" & aaa & ">" & 555 & "</" & aaa & ">")
--
answer "\<" & aaa & "\>" & 555 & "\</" & aaa & "\>"
--
put "<aaa>" & 555 & "</aaa>" into myString
put replaceText(myString, "<", "<") into myString
put replaceText(myString, ">", ">") into myString
answer myString
--
Re: Using expressions with "<" and ">"
Code: Select all
put "jim" into aaa
put "<" & aaa & ">" & 555 & "</" & aaa & ">" into fld 1
answer the htmltext of fld 1
Re: Using expressions with "<" and ">"
This is my kind of action.
And if one is going to fake it, at least try to keep it in the ballpark.
Jimi nailed it, mostly.
Playing around a bit, anyone tell me why:
works, but this, which seems to me pretty much the same, does not:
Both a field and a variable are a container. So a field must have "properties" that a variable does not, especially when dealing with text, or in this case, htmlText. This is my kind of action because this is an instance where I see that "container" is not all-inclusive. That is, there are two kinds of container.
I thought that a "do" construction might work on the variable version, but it does not seem to. There is something besides inadequate levels of evaluation that a field does with text that a variable does not.
Craig
And if one is going to fake it, at least try to keep it in the ballpark.

Jimi nailed it, mostly.
Playing around a bit, anyone tell me why:
Code: Select all
put "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into fld 1
answer the htmlText of fld 1
Code: Select all
put "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into temp
answer the htmlText of temp
I thought that a "do" construction might work on the variable version, but it does not seem to. There is something besides inadequate levels of evaluation that a field does with text that a variable does not.
Craig
Re: Using expressions with "<" and ">"
Craig-
Variables don't have "properties", so "the htmlText of" a variable doesn't exist.
You can set and retrieve the htmlText of a field because it's a property you can manipulate.
A variable is just a container for a value, nothing more or less.
Variables don't have "properties", so "the htmlText of" a variable doesn't exist.
You can set and retrieve the htmlText of a field because it's a property you can manipulate.
A variable is just a container for a value, nothing more or less.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Using expressions with "<" and ">"
I had little hope for this, but had to try:
Nope.
So placing the text string into a field and then into a variable did not "format" the string in any way, or at least whatever "advantages" or "differences" the string had by virtue of living in a field were lost when transferring to a variable.
What is different when extracting "the htmlText" from a field rather than from a variable?
Craig
Code: Select all
put "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into fld 1
put fld 1 into temp
answer the htmlText of temp
So placing the text string into a field and then into a variable did not "format" the string in any way, or at least whatever "advantages" or "differences" the string had by virtue of living in a field were lost when transferring to a variable.
What is different when extracting "the htmlText" from a field rather than from a variable?
Craig
Re: Using expressions with "<" and ">"
Mark.
What threw me was I read the construction of the string itself as "containing" the htmlText information intrinsically. Not so.
I guess that makes sense. So conceptually, for me always a challenge, the string "inherits" the htmlText property from a field. The string is always just a string.There are indeed more than one "kind" of container, in that there are different properties among containers. Variables have a text properly, as does a field, but not an htmlText property.
Just thinking out loud...
OK, I feel better. Thanks.
Craig
What threw me was I read the construction of the string itself as "containing" the htmlText information intrinsically. Not so.
I guess that makes sense. So conceptually, for me always a challenge, the string "inherits" the htmlText property from a field. The string is always just a string.There are indeed more than one "kind" of container, in that there are different properties among containers. Variables have a text properly, as does a field, but not an htmlText property.
Just thinking out loud...
OK, I feel better. Thanks.
Craig
Re: Using expressions with "<" and ">"
The original didn't work for me, but there was a syntax error in the html. I removed the slash from "</" just before the second instance of "aaa". This works for me:
answer "<" & aaa & ">" & 555 & "<" & aaa & ">"
answer "<" & aaa & ">" & 555 & "<" & aaa & ">"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Using expressions with "<" and ">"
Jacque.
Good find. I don't use HTML so I never would have known it was wrong.
But Klaus, how does this play into what you said, about "answer" dialogs being very particular about html-formatted strings?
Craig
Good find. I don't use HTML so I never would have known it was wrong.
But Klaus, how does this play into what you said, about "answer" dialogs being very particular about html-formatted strings?
Craig
Re: Using expressions with "<" and ">"
Maybe i was not very precise in what I said:
then:
you "don't use HTML".
should read ... and ends with a HTML end tag -> </xxx> (remember that LC first resolves the complete string)... if a string starts with < and ends with >
then:
Or just treat it like a pair of <p> and </p>, at least LC presumes this to be HTML, no matter ifLC will see this as HTML tags and if LC does not know the actual tag(s), it only supports a
very basic set of HTML tags, it will just neglect them.
you "don't use HTML".

Re: Using expressions with "<" and ">"
I wouldn't have caught the error either if I hadn't got an error message when testing it using "do" which also didn't work. The dictionary says:
I know that concatenation turns text into plain strings, but then why did the original example not stay as a string? It did have a legitimate tag ooen/close pair. Curious.
The </ was used as a tag opener, which is wrong, it's an end designator. So I assume that was the error. But that doesn't explain why LC didn't see the prompt as html after the fix, because after the fix it still is.The prompt can be either formatted text (in the htmlText property's format) or plain text. If the prompt contains <p> or a start/end tag pair, the answer command assumes the text is in the same format as the htmlText property. Otherwise, the answer command assumes the text is plain text.
I know that concatenation turns text into plain strings, but then why did the original example not stay as a string? It did have a legitimate tag ooen/close pair. Curious.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Using expressions with "<" and ">"
IIRC the original rule for LC to treat Ask and Answer prompts as htmlText was to require what all htmlText has: "<p>" at the beginning and "</p>" at the end.
Resuming that rule would allow other uses.
If the rule has not formally changed perhaps this is a bug.
Resuming that rule would allow other uses.
If the rule has not formally changed perhaps this is a bug.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn