-2

I've been looking at a few of these questions on StackOverflow but can't seem to work out why I can't get any of the resolutions working.

I have the following code:

Imports System
                
Public Module Module1
    Public Sub Main()
        dim myFirstName as string = "John"
        dim myLastName as string = "Smith"
        
        dim name as string = String.Format("<Person FirstName=\"{0}\" LastName=\"{1}\">", myFirstName, myLastName)
    End Sub
End Module

and I'm passing in two variables that need to be enclosed in double quotes.

I keep getting an error for comma ) or another expression continuation continued.

I've got this on .Net Fiddle to try and replicate this.

https://dotnetfiddle.net/jpDL04

Aiden
  • 179
  • 2
  • 13
  • If you are using VS2015 or later, you could use `Dim name = $""`. More info: [Interpolated Strings](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/interpolated-strings). – Andrew Morton Dec 22 '21 at 18:11

2 Answers2

2

Try this:

dim name as string = String.Format("<Person FirstName=""{0}"" LastName=""{1}"">", myFirstName, myLastName)

Using 2 double-quotes instead. The backslash is a C# escape.

Justin Tolchin
  • 423
  • 5
  • 16
0

Use Embedded Expressions is an option

Module Program
    Sub Main(args As String())
        Console.Title = "Code sample"
        Dim myFirstName As String = "John"
        Dim myLastName As String = "Smith"
        Dim name = (<T><%= Chr(60) %>Person FirstName="<%= myFirstName %>" LastName="<%= myLastName %>"<%= Chr(62) %></T>).Value
        Console.WriteLine(name)
        Console.ReadLine()
    End Sub
End Module
Karen Payne
  • 4,341
  • 2
  • 14
  • 31