Jump to content
Sign in to follow this  

Cannot concatenate '&' ampersand in a string

Recommended Posts

I have found no way to resolve concatenation with '&' symbol, as it is ignored in the concatenation by both vs.AlrtDialog(vs.Concat()) and +

I have also tried the folloinwing:

amp = str.replace('&', '%26')

but no success.

any suggestion?


Share this post

Link to post

Have you tried escaping it? like '\&' + 'The rest of the string.' I have never had this, so I don't know if that's the issue here.

TIP: In Python, it's better/easier/more readable to use string format:

'This is my string: %s & %s' % ('My String', MyObject)

Where %s will be replaced by the string representation of the things inside the tuple.

Share this post

Link to post

Hi Dieter,

yes I tried that..

What turned out is that the & was actually concatenated in the string, but for some reason vs.AlrtDialog does not display it.

as I was using vs.AlrtDialog to check the string, it took me a while to figure out that actually & was there..

and thanks once more for your TIP, it's all very appreciated as I've still got so much to learn about Python!


Share this post

Link to post

Hi Dieter,

yes, I have tried vs.Chr(38) but it behaves in the same way:

The following displays correctly:

amp = vs.Chr(38)
vs.AlrtDialog(vs.Concat('ampersand = ', amp))

but when i use concatenation (either vs.Concat or python native +) AlrtDialog doesn't display the ampersand.

Bu then I used the concatenated string to make a http call I realised that all my ampersand were there as expected...

Share this post

Link to post


It's been 5 months, and you may already have the answer, but for those that don't...

This is not a Python problem, but rather a quirk of the AlrtDialog() call, and possibly its Modern Dialog underpinnings.

Use two ampersands '&&' to show a single ampersand in an Alert Dialog string.

Use a single ampersand '&' in Message() command strings and in normal string use.

This holds true for both Python and VectorScript when using AlrtDialog().



vs.AlrtDialog('Watch out for Alligators && Snakes!!!')
vs.Message('Good luck avoiding Death & Taxes!!!')


forAlrt = True
S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers')

forAlrt = False
S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers')



  • Like 1

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

  • Create New...