String issues

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

String issues

Post by JackieBlue1970 » Mon Jul 27, 2020 11:03 pm

I'm perplexed on this one. I am testing an call to eBay's API, a very simple one. The XML code is submitted with headers. I found it was not working, even though the XML is right. I was building the XML up with strings and found that it doesn't work as the logic would indicate:

Code: Select all

put "<?xml version='1.0' encoding='utf-8'?>" into xStep1
   put xStep1 & "<GeteBayOfficialTimeRequest xmlns='urn:ebay:apis:eBLBaseComponents'>  " into xStep2
   put xStep2 & "<RequesterCredentials>" into xStep2a
   put xStep2a & "<eBayAuthToken> WTF </eBayAuthToken>" into xStep2b
   put xStep2b & "<ErrorLanguage>en_US</ErrorLanguage>" into xStep3
   put xStep3 & "<WarningLevel>High</WarningLevel>" into xStep4
   put xStep4 & "</GeteBayOfficialTimeRequest>" into xPayload

   answer "Payload  " & xPayLoad
   answer "Step1  " &  xStep1
   answer "step2  " & xStep2
   answer "step2a  " & xStep2a
   answer "step2b  " & xStep2b
   answer "Step3  " & xStep3
   answer "Step4  " & xStep4
It returns just the text WTF when I answer xStep2b. And continues to omit the previous strings that I am concatenating. What am I missing here? Yes, I know about merge but that shouldn't make any difference when concatenating strings. TIA. JackieBlue

Image
Image
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: String issues

Post by richmond62 » Tue Jul 28, 2020 10:23 am

I'm not a big fan of 'answer', so I bunged the first part of your script into a button
and then asked it to dump the end result into a field:

Code: Select all

on mouseUp
   put "<?xml version='1.0' encoding='utf-8'?>" into xStep1
   put xStep1 & "<GeteBayOfficialTimeRequest xmlns='urn:ebay:apis:eBLBaseComponents'>  " into xStep2
   put xStep2 & "<RequesterCredentials>" into xStep2a
   put xStep2a & "<eBayAuthToken> WTF </eBayAuthToken>" into xStep2b
   put xStep2b & "<ErrorLanguage>en_US</ErrorLanguage>" into xStep3
   put xStep3 & "<WarningLevel>High</WarningLevel>" into xStep4
   put xStep4 & "</GeteBayOfficialTimeRequest>" into xPayload
   ----
   put xPayload into fld "ff"
end mouseUp
Which it did:

"<?xml version='1.0' encoding='utf-8'?><GeteBayOfficialTimeRequest xmlns='urn:ebay:apis:eBLBaseComponents'> <RequesterCredentials><eBayAuthToken> WTF </eBayAuthToken><ErrorLanguage>en_US</ErrorLanguage><WarningLevel>High</WarningLevel></GeteBayOfficialTimeRequest>"

I then extended that code to dump each of the steps you are checking into the lines of a listField:

Code: Select all

on mouseUp
   put "<?xml version='1.0' encoding='utf-8'?>" into xStep1
   put xStep1 & "<GeteBayOfficialTimeRequest xmlns='urn:ebay:apis:eBLBaseComponents'>  " into xStep2
   put xStep2 & "<RequesterCredentials>" into xStep2a
   put xStep2a & "<eBayAuthToken> WTF </eBayAuthToken>" into xStep2b
   put xStep2b & "<ErrorLanguage>en_US</ErrorLanguage>" into xStep3
   put xStep3 & "<WarningLevel>High</WarningLevel>" into xStep4
   put xStep4 & "</GeteBayOfficialTimeRequest>" into xPayload
   ----
   put xPayload into fld "ff"
   --
   put "Step1" && xStep1 into line 1 of fld "fSTEPS"
   put "Step2" && xStep2 into line 2 of fld "fSTEPS"
   put "Step2a" && xStep2a into line 3 of fld "fSTEPS"
   put "Step2b" && xStep2b into line 4 of fld "fSTEPS"
   put "Step3" && xStep3 into line 5 of fld "fSTEPS"
   put "Step4" && xStep4 into line 6 of fld "fSTEPS"
end mouseUp
Now this does NOT sort out your 'answer' problem, but it DOES give you the sort of feedback you are looking for. 8)
-
Screenshot 2020-07-28 at 12.22.14.png
-
Do hope your string issues get sorted out.
-
knot.jpg
knot.jpg (4.5 KiB) Viewed 6747 times
Attachments
concat.livecode.zip
Here's the stack.
(1.24 KiB) Downloaded 154 times

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

Re: String issues

Post by Klaus » Tue Jul 28, 2020 11:39 am

Hi Jackie,

I guess the following:
Since the ASK and ANSWER dialogs are aware of possible HTMLtags in the "string to answer" like
-> answer "<b>Text in bold</b>"
it may try to interpret the strings in <> as HTML tags and since the support for HTML(tags) is very basic in LC,
it simply omits all unknow tags.

That's why you only see the text outside of the <> tags and the reason why Richmond's way
to put the strings into fields gives the exspected result.


Best

Klaus

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: String issues

Post by JackieBlue1970 » Tue Jul 28, 2020 2:12 pm

Thanks. Strange behavior. I keep running into strange behaviors with LiveCode. Honestly, I would consider this a bug since the information is enclosed in quotes and should be interpreted as a string literal, not HTML. Very, very whacked.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: String issues

Post by richmond62 » Tue Jul 28, 2020 3:26 pm

JackieBlue1970 wrote:
Tue Jul 28, 2020 2:12 pm
Thanks. Strange behavior. I keep running into strange behaviors with LiveCode. Honestly, I would consider this a bug since the information is enclosed in quotes and should be interpreted as a string literal, not HTML. Very, very whacked.
Well, possibly what you term "strange behaviors" is just you interpreting LiveCode in the light
of other programming languages you have worked with.

To be honest, while I got your strings into "some sort of something" that allowed you to check what was going on,
were I to do that sort of thing I would tend to strip out the "<" and the ">" as they do look a bit like control characters
even when embedded in quotes.

Of course, if you need the "<" and the ">" [thinks: XML] then don't get "all fussed" about answer boxes and learn to use listFields. 8)
that it doesn't work as the logic would indicate
What fusses me about that statement is the use of the definite article ('the'), as I'm not sure which logic
you are referring to; had you stated:

"that it doesn't work as logic would indicate" your statement would have seemed more logical and
less subjective.

A long, long time ago (well 1975) I learnt a language called FORTRAN IV (nowadays they'd call teaching FORTRAN IV to
13 year old kids child abuse) and, very shortly after that I learnt an early form of BASIC. BASIC was supposed to be easier for
young kids to get their heads round: and I suppose it might have been for kids who had not learnt FORTRAN IV first.
But as my head was stuffed with all the "guff" from FORTRAN IV a lot of BASIC seemed "silly". . .

. . . oddly enough I can still remember BASIC (and use it for recreational purposes on my 2 BBC Micro computers), but
FORTRAN IV has evaporated like the morning dew. 8)
Very, very whacked.
Where I come from that means 'tired'.

Do you mean 'tired' or something rather stronger?

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: String issues

Post by JackieBlue1970 » Tue Jul 28, 2020 3:38 pm

Putting into the fields worked for my purposes and quickly let me diagnose and address the testing issues. But, the handling of string literals is very strange compared to other languages. As you surmised, it is XML, which is just formatted text. Other languages treat them as text/strings, period, end of story. But, LC is not other languages and has to be different. I guess maybe it is more accessible than other languages for beginners. I do find it interesting that many on these forums give LC a pass on things like this and try to justify it as better. I think it sows confusion and makes experienced programmers turn away from it, as was discussed in the "Off Topic" forum recently. But, I find I do enjoy it overall and love that there are much fewer frameworks and other nonsense that are included in many programming environments today.


BTW - in my cultural context (American born in 1970) "whacked" means "crazy".

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: String issues

Post by richmond62 » Tue Jul 28, 2020 3:44 pm

Perhaps it is helpful if you remember that LiveCode does not distinguish between string variables and numeric variables.
BTW - in my cultural context (American born in 1970) "whacked" means "crazy".
Quite possibly: LiveCode has grown out of HyperCard, a programming environment that was initially thought
of as a sort of "anti-programming language" for types who couldn't be bothered or didn't have the time to
get "down and dirty" with the more traditional types pf programming languages. So, Yes, it can seems "odd" or
"bonkers" if you are coming from a heavy involvement in those types of language.

Interestingly enough a lot of young people who have had their first taste of programming using LiveCode with me have gone on to
study C++, C# and so on at University and tell me that what they learnt with me with LiveCode accelerated their learning with those
languages.

Maybe "your problem" is that you did things the other way round. :?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: String issues

Post by dunbarx » Tue Jul 28, 2020 5:33 pm

BTW - in my cultural context (American born in 1970) "whacked" means "crazy".
I always thought that "whacked" meant murdered. American, 1951.

Craig

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

Re: String issues

Post by Klaus » Tue Jul 28, 2020 5:38 pm

JackieBlue1970 wrote:
Tue Jul 28, 2020 3:38 pm
...
But, the handling of string literals is very strange compared to other languages. As you surmised, it is XML, which is just formatted text. Other languages treat them as text/strings, period, end of story.
This is also the case in LC, you have just been hit by a special "feature" of the ASK and ANSWER dialogs!

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: String issues

Post by JackieBlue1970 » Tue Jul 28, 2020 6:20 pm

dunbarx wrote:
Tue Jul 28, 2020 5:33 pm
BTW - in my cultural context (American born in 1970) "whacked" means "crazy".
I always thought that "whacked" meant murdered. American, 1951.

Craig
It does as a verb - as in "to get whacked". Mostly heard in movies about organized crime. If it is about street gangs you usually here "pop a cap" as in "pop a cap in his head". Mind you this is in entertainment as I have no experience with organized crime or gangs. I live in a rural area and most of this crime is in large cities, usually in a few neighborhoods. Of course, we do have drugs (mostly meth) in the country. Not many homicides though (we have had 1 this year, 1 last year, which was committed by an insane person).

JackieBlue1970
Posts: 64
Joined: Thu Jan 16, 2020 10:28 pm
Location: Max Meadows, VA USA

Re: String issues

Post by JackieBlue1970 » Tue Jul 28, 2020 6:22 pm

richmond62 wrote:
Tue Jul 28, 2020 3:44 pm
Perhaps it is helpful if you remember that LiveCode does not distinguish between string variables and numeric variables.
BTW - in my cultural context (American born in 1970) "whacked" means "crazy".
Quite possibly: LiveCode has grown out of HyperCard, a programming environment that was initially thought
of as a sort of "anti-programming language" for types who couldn't be bothered or didn't have the time to
get "down and dirty" with the more traditional types pf programming languages. So, Yes, it can seems "odd" or
"bonkers" if you are coming from a heavy involvement in those types of language.

Interestingly enough a lot of young people who have had their first taste of programming using LiveCode with me have gone on to
study C++, C# and so on at University and tell me that what they learnt with me with LiveCode accelerated their learning with those
languages.

Maybe "your problem" is that you did things the other way round. :?
Definitely since my programming was BASIC, then Hex (Hexadecimal Machine Language) before moving on to Pascal, C/C++, VB3/6 and .Net and then some Python and PHP (my god PHP is really whacked :D !)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: String issues

Post by richmond62 » Tue Jul 28, 2020 6:35 pm

Definitely since my programming was BASIC, then Hex (Hexadecimal Machine Language) before moving on to Pascal, C/C++, VB3/6 and .Net and then some Python and PHP (my god PHP is really whacked :D !)
I am so, so glad I cannot remember any programming I did on a ZILOG. 8)

When I was at High School (1975-1980) the school, thinking, as a private school, it
was no-end of posh (which it really wasn't) invested in 1977 in something called a Research Machine 380Z:
-
oldCrap.jpg
oldCrap.jpg (7.8 KiB) Viewed 6638 times
-
and jacked it into the back of a monochrome TV . . .

The headmaster (who was a pillock - there's a British English word you can have fun adding to your lexicon) devoted a whole
classroom to this machine and issued all the spotty teenagers (myself included) with monster 8 inch floppy disks:
-
bigFlop.jpg
bigFlop.jpg (5.04 KiB) Viewed 6638 times
-
of course, after a week of "young prawns" going into the room and finding out that getting more than a dull farting noise
out of the machine actually required some application, the machine was moved to a small erstwhile cleaning cupboard and yours truly
(useless at sports, wrong social class. awkward "erk") was appointed "computer prefect" and given the key.
So, when I wasn't running round the hills in army uniform (Sergeant Mathewson, terror and general twat of the Combined Cadet Force),
I was closeted in the cupboard (marvellous way to avoid Rugby, Cricket, Hockey, Athletics and other pointless sports)
hammering away at the 380Z . . .

It didn't do my hairstyle much good:
-
teenageShocker .jpg
Last edited by richmond62 on Tue Jul 28, 2020 6:50 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: String issues

Post by FourthWorld » Tue Jul 28, 2020 6:41 pm

JackieBlue1970 wrote:
Tue Jul 28, 2020 3:38 pm
As you surmised, it is XML, which is just formatted text. Other languages treat them as text/strings, period, end of story.
As it is with LC as well.

Strings are strings. Reliably and predictably, as one expects in any language.

What you're seeing isn't about LC's strings at all, but a by-product of the specific choice of user interface element chosen to display it.

As you've seen, you can put the contents into any field, observe the variables in the debugger, and through any other means, and in all cases the string you expect to see is what you see.

But if you choose to use the ask and answer dialogs specifically, you'll encounter this feature described in the Dictionary:
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.
https://livecode.com/resources/api/#liv ... ipt/answer

Note that even then it isn't changing the string, merely interpreting it to change how the string is displayed in that momentary dialog.

The ability to use inline tags for styling the text in those user interface elements is a godsend. But to make that happen, LC has to examine the string passed to it for XML-style tags.

The ask and answer dialogs are great choices for communicating with the end-user, but in addition to this string interpretation feature they're also modal, making them cumbersome for working with in development, reducing the workflow to Enter Enter Enter Enter Enter.

There are more enjoyable ways to check your values in development:
- Use a field, as you've done.
- Use the simple "put" command, to display in the Message Box
- Use the debugger, designed for exactly this sort of observation.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: String issues

Post by jacque » Tue Jul 28, 2020 6:49 pm

A short layman's explanation: the ask and answer dialogs take a quoted string literal as a parameter. When displaying the content the quotes are stripped off and the content examined to see if it is html or plain text.

You can also pass a variable as the content without the quotes but it will be parsed the same way. You might be able to pass a variable with quotes, I haven't tried it to see what happens.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: String issues

Post by richmond62 » Tue Jul 28, 2020 6:53 pm

Err . . . even shorter:
this feature described in the Dictionary
Always read the instructions on the packet.
-
lcMED.png
lcMED.png (8.82 KiB) Viewed 6634 times

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”