Author Topic: VirtualTag: Replacing first or last comma with "&"  (Read 1376 times)

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
Right now ";" is a demarcating character that splits fields.  For example, say <Artist> has the value "foo1; foo2; foo3", MB will treat it as three different artists.  When presenting that field I use $Replace(<Artist>,";",",") resulting in "foo1, foo2, foo3" displayed.  Is there a way to replace the last comma with an "&" or "and" whether there's two artists or five?

redwing

  • Guest
It's not easy due to the special way MB treats multi-value tags. This is what I've come up with. If somebody knows a way to simplify this further, please let me know:

$If($First(<Artist>)=<Artist>,<Artist>,$Replace($Replace(<Artist>*,"; "$RSplit(<Artist>,;,1)*,),;,",")" & "$RSplit(<Artist>,;,1))

theta_wave

  • Sr. Member
  • ****
  • Posts: 680
Thanks redwing.  Actually, your code helped simplify some of my virtualtags such as the one below:

Code
$If(<Artist>="+/-",<Artist>,$If(<Artist>="20/20",<Artist>,$If(<Artist>="AC/DC",<Artist>,$If(<Artist>="Ambidextrous/Morkva",<Artist>,$If(<Artist>="Broker/Dealer",<Artist>,$If(<Artist>="De/Vision",<Artist>,$If(<Artist>="etti/etta",<Artist>,$If(<Artist>="MorelenbaumĀ² / Sakamoto",<Artist>,$Replace($Replace($Replace(<Artist>,;,", "),/,", "),"  "," ")))))))))