Substring function incorrectly defined in language reference?


Author
Message
Sercan
Sercan
Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)Partner Member (728 reputation)
Group: Forum Members
Posts: 23, Visits: 112
I am trying to pull a single character at index values.trialcount from a long character string values.sequence. This does not work (suggested by the help file):
values.trialtype = substring(values.substring, values.trialcount,values.trialcount);

Neither does this (suggested by the inquisit tooltip):
values.trialtype = values.sequence.substring(values.trialcount,1);

What should I do?


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 85K
Sercan - 9/20/2022
I am trying to pull a single character at index values.trialcount from a long character string values.sequence. This does not work (suggested by the help file):
values.trialtype = substring(values.substring, values.trialcount,values.trialcount);

Neither does this (suggested by the inquisit tooltip):
values.trialtype = values.sequence.substring(values.trialcount,1);

What should I do?


The substring function works as detailed in the documentation.

https://www.millisecond.com/support/docs/current/html/language/expressions/functions.htm



It takes three parameters:
(1) The string you want to extract a substring from.
(2) The start index of the substring you want to extract within the string. Note that the string index is zero-based.
(3) The length of the substring you want to extract from the string.

That is, with

<values>
/ sequence = "abcd"
</values>


substring(values.sequence, 0, 1)


will return "a"

substring(values.sequence, 1, 1)


will return "b"

substring(values.sequence, 2, 1)


will return "c"

and

substring(values.sequence, 3, 1)


will return "d".

In code:

<values>
/ sequence = "abcd"
/ trialcount = 0
/ substring = ""
</values>

<trial exampletrial>
/ ontrialbegin = [
    values.trialcount += 1;
    values.substring = substring(values.sequence, values.trialcount-1, 1);
]
/ stimulusframes = [1=exampletext]
/ validresponse = (57)
</trial>

<text exampletext>
/ items = ("<%values.substring%>")
</text>

<block exampleblock>
/ trials = [1-4 = exampletrial]
</block>


Edited Last Month by Dave
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search