GioPet Posted December 14, 2015 Share Posted December 14, 2015 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? g Quote Link to comment
Dieter @ DWorks Posted December 15, 2015 Share Posted December 15, 2015 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. Quote Link to comment
GioPet Posted December 16, 2015 Author Share Posted December 16, 2015 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! G Quote Link to comment
Dieter @ DWorks Posted December 16, 2015 Share Posted December 16, 2015 Have you already tried vs.Chr(38)? As it's VS specific, I guess it will be escaped like vs expect it. Quote Link to comment
GioPet Posted December 16, 2015 Author Share Posted December 16, 2015 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... Quote Link to comment
MullinRJ Posted May 28, 2016 Share Posted May 28, 2016 Giovanni, 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(). Examples: 1) vs.AlrtDialog('Watch out for Alligators && Snakes!!!') vs.Message('Good luck avoiding Death & Taxes!!!') 2) forAlrt = True S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers') vs.AlrtDialog(S) forAlrt = False S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers') vs.Message(S) HTH, Raymond 1 Quote Link to comment
Recommended Posts
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.