Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Questions and Answers >> Extra (unwanted) characters in DisplayExpression
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1467306777

Message started by Marianne Høyen on Jun 30th, 2016, 1:12pm

Title: Extra (unwanted) characters in DisplayExpression
Post by Marianne Høyen on Jun 30th, 2016, 1:12pm

I try to change a $DisplayExpression for the title of my notes.

As key attribute I have

Firstattribute  Cat
Secondattribute Dog

I want the result to be Cat: Dog

However, when I in the title pane of the text writes $Firstattribute+": "+$Secondattribute the result is

Cat;:;Dog

?

I have copy-pasted the information Cat and Dog from another system, and I suspect that doing this introduced some unwanted 'dirt'.

Do some of you have any suggestions about how to get rid of that?

BW

Marianne

[edit][admin edit - fixed unintended smiley in example problem output code. How? Tick the "Check this if you'll be adding code (or don't like smilies)." box at the bottom of the message editing page, i.e. under where you type your message][/edit]

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Mark Anderson on Jun 30th, 2016, 2:34pm

Experimenting, it looks like your $Firstattribute (possibly both) are list attributes, i.e. a List or Set Type.

In the following my user attribute names show the data type used. I set $MyString1 to "Cat", $MyString2 to "Dog" and $MyList to "Cat". Now as you did I typed a display expression into the window on the Text Inspector. Typing in:

$MyString+": "+$MyString2

gives: Cat: Dog

$MyList+": "+$MyString2

gives: Cat;:;Dog

The latter is because Tinderbox thinks you're trying to add to a list. We can get around this (presuming the first attribute must be a list) thus:

eval($MyList)+": "+$MyString2

The eval() call evaluates the list value to a string so normal concatenation of strings (i.e. joining of texts) happens as expected.

~~~
LATER... Mark B, has since noted a better option for List/Set data in the above scenario. In stead of eval, use:

$MyListOrSet.format(", ")+": "+$MyString2

The format command takes the list and inserts the formatting sting - here a comma+space - between each list item.  If the list has only one item as here, you just get back the value!

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Marianne Høyen on Jun 30th, 2016, 2:49pm

You're right! The eval() worked fine.

I found that using other than pre-defined attributes doesn't cause the same problem....

BW
Marianne

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Mark Bernstein on Jun 30th, 2016, 3:49pm

Are you sure you want these to be list attributes?

- - -

I'm not wild about this use of eval.  A better way to coerce a list to a string is

  $MyList.format(",")

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Mark Anderson on Jun 30th, 2016, 3:54pm

The underlying issue is the Data type of the attribute. The problem you originally described should only occur with List or Set types.

If you want to know the data type of an attribute, you can look at it in the Inspector. For system (built-in) attributes, you may find this list a quicker way to look things up.

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Marianne Høyen on Jul 1st, 2016, 2:55am

OK - no, I don't want lists. It just happens.

I use Authors and Booktitle which both in the list, you refer to, are listed as set. Why do they act as lists, do you think? I alto use some user-defined attributes Then the problem does not appear.

A solution might be not to use reference attributes at all. TBX makes a wrong import (I have emailed to support about this problem, and they told me that the implementation of references were ad hoc and would be corrected in a future version of TBX (issue 1818)).

Title: Re: Extra (unwanted) characters in DisplayExpression
Post by Mark Anderson on Jul 1st, 2016, 3:50am

When I spoke generically of a 'list' I was referring to all attribute that supports multiple values. Two of the attribute Data type in Tinderbox support multiple values: List or Set types. I commend following those links and reading the articles and exploring out from there in aTbRef. The main difference between Lists and Sets is sets do not support duplicate values.  If the 2 value of a List or Set were "Cat;Dog" (semi-colon is the value delimiter) then adding the value "Cat" would result in a List value of "Cat;Dog;Cat" but a Set would have the result "Cat;Dog" as the duplicate is ignored.

$Authors needs to be multi-value as a reference (book, paper, etc.) often has—outside fiction—more than one author. More specifically it is a Set-type attribute as duplicates in the attributes stored value(s) would be inappropriate.

So I don't see a mistake her.  If you look up what Set and List type do you'll see they are appropriate and that Set is a correct data type with $Authors.

The real issue here is that a single item list is still, under the hood, see a list consisting of one item. When using list attributes (i.e. List or Set data types) in action code you need to be aware that a reference to the attribute, e.g.$Authors, reference all values and you may need to use .format() to turn the value(s) into a string

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.