fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: How to mask { and } in a string

How to mask { and } in a string 7 months 2 weeks ago #6458

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1515
Hello,

I'm trying to build a connection string like this:
String.Format( "Driver={Microsoft access Driver (*.mdb)};Dbq={0};Uid=Admin;Pwd=;", cDatabase )
But it gives a runtime error because of the parentheses { and }.

Is there any possibility to mask them?

TIA

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

How to mask { and } in a string 7 months 2 weeks ago #6459

  FFF's Avatar FFF Online Posts: 554
Wolfgang,
FUNCTION Start() AS VOID
LOCAL c AS STRING
c:="Driver={Microsoft access Driver (*.mdb)};Dbq={0};Uid=Admin;Pwd=;"
Console.WriteLine(c)
RETURN

works for me.
Seems i miss the point ;)
EDIT Obviously.
BTW, there should be a "Delete" button for own posts...

Adding an "i" wouldn't be of use?

Please Log in or Create an account to join the conversation.

Last edit: by FFF. Reason: bs

How to mask { and } in a string 7 months 2 weeks ago #6460

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1515
Hi Karl,

if you add a String.Format() and a parameter, it fails.

The same is occurring when using the prefix "i".

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

How to mask { and } in a string 7 months 2 weeks ago #6461

  robert's Avatar robert Offline Posts: 946
Wolfgang, you can escape the { and } characters by adding two of them in a row, so you will have to write:

"Driver={{Microsoft access Driver (*.mdb)}};Dbq={0};Uid=Admin;Pwd=;"

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

How to mask { and } in a string 7 months 2 weeks ago #6462

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1515
Hi Robert,

thank you very much! This works.

Thank you again.

Wolfgang

P.S. this is used in a X# monitoring service that will go into production on Monday
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

How to mask { and } in a string 7 months 2 weeks ago #6463

  Jamal's Avatar Jamal Offline Posts: 83
I don't know about X#, but in C# whenever you want certain characters like \ in a string, I used the @ sign prefix.

For example: @"\programs files\test"

otherwise I have to write @"\\program files\\test"

Jamal

Please Log in or Create an account to join the conversation.

Last edit: by Jamal.

How to mask { and } in a string 7 months 2 weeks ago #6464

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1515
Hi Jamal,

normally this works also in X# (but with the prefix 'e' instead of '@'), but this does no worked for the '{' character.

The answer from Robert helped, doubling the '{' and the '}' character solved the problem.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

How to mask { and } in a string 7 months 2 weeks ago #6465

  Chris's Avatar Chris Offline Posts: 1109
Hi Jamal,

In X#, it's the opposite of c#. c# uses escaped strings by default and you need to use @ in order to make them "regular" strings. In X#, literal strings are "regular" by default, and you need to prefix them with e to make them escaped.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1