A small question about accessing a character in a string
Posted: Thu Feb 11, 2021 6:03 pm
I have an array variable with a range of different kinds of data in the array elements. One element, call it myArray["identity"], contains a text string.
To access a particular character in that string, I would write code like this:
However, as a LiveCode beginner, I reverted to habits from other programming languages and inadvertently wrote code like this:
This code was not flagged as an error, and it seemed to execute correctly. In fact, I didn't even discover this unusual code until about two weeks after writing it.
I've not been able to find a small test case to demonstrate this. So my conclusion is that this code might not cause an error, but it always yields empty as a result, and, coincidently, empty was an acceptable value at that point in my project.
Is there another explanation?
To access a particular character in that string, I would write code like this:
Code: Select all
if char 5 of myArray["identity"] is "X" then ...
Code: Select all
if myArray["identity"][5] is "X" then ...
I've not been able to find a small test case to demonstrate this. So my conclusion is that this code might not cause an error, but it always yields empty as a result, and, coincidently, empty was an acceptable value at that point in my project.
Is there another explanation?