Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there any way to write long strings in VB.NET?
Message
From
17/02/2012 09:41:53
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01535583
Message ID:
01535666
Views:
42
>>>>>Hi everybody,
>>>>>
>>>>>In C# I can use this syntax
>>>>>
>>>>>string myString = @"My very long
>>>>>multi line
>>>>>string";
>>>>>
>>>>>Is there anything like this in VB.NET or I have to split my command using + sign?
>>>>
>>>>
>>>>Think you have to split
>>>>
>>>>
>>>>    Sub Main()
>>>>		Dim s As String = "abc " _
>>>>			  & "ppp " _
>>>>			  & "qqq"
>>>>
>>>>
>>>>
>>>>		Console.WriteLine(" {0}", s)
>>>>		Console.ReadLine()
>>>>
>>>>    End Sub
>>>>
Hi,
>>>I don't think the line continuation character is needed if you place the ampersand (or plus sign) at the end of the 'line'. e.g.
Dim s As String = "abc " &
>>>"ppp " &
>>>"qqq"
>>
>>Didn't know that - neither did I know the
>>
>><string>
>>zzz
>></string>.Value
>>
But me and VB, eh
>>
>>
>>>Just one of those VB things :-{ . But you and Craig are right in saying StringBuilder isn't a good option in this situation...
>>
>>Nowhere in this thread did I mention StringBuilder - I did in the past
>>
>>It's all about optimization. Using a StringBuilder also creates an object that has to be garbage collected
>
>My understanding of StringBuilder has always been that it is lightning fast, something like 700 times faster than its predecessor. Is that incorrect? Or does it depend?

It depends ;-}
string s = " "+" "+" "+" " will be faster than SB.
string s= " " ; s+=" " ; s+= " " ; s+=" "; will be slower.

Also bear in mind that using the StringBuilder.Insert(), Remove() and Replace() methods will outperform the String. versions....
Previous
Reply
Map
View

Click here to load this message in the networking platform