|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Embedding a newline in a vb.net string constantIs it possible to embed a newline constant in a string in the same way
as c#? I really don't want to do something like this: ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) when I should be able to do ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) Not the best example, I am sure, but it does get worse in many cases? So, is there a way to do this in vb, or am I stuck? I have tried googling but I can't find anything. Thanks, Andrew On 6 Dec 2006 10:08:48 -0800, Andrew Backer wrote:
> Is it possible to embed a newline constant in a string in the same way Instead of vbcrlf use Environment.NewLine> as c#? I really don't want to do something like this: > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > when I should be able to do > ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > > Not the best example, I am sure, but it does get worse in many cases? > So, is there a way to do this in vb, or am I stuck? I have tried > googling but I can't find anything. > > Thanks, > Andrew The question is how do I embed it in the string.
If there is some magic regarding this the env constant that will make this happen, I think I still need some illumination. // Andrew Rad [Visual C# MVP] wrote: Show quoteHide quote > On 6 Dec 2006 10:08:48 -0800, Andrew Backer wrote: > > > Is it possible to embed a newline constant in a string in the same way > > as c#? I really don't want to do something like this: > > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > > when I should be able to do > > ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > > > > Not the best example, I am sure, but it does get worse in many cases? > > So, is there a way to do this in vb, or am I stuck? I have tried > > googling but I can't find anything. > > > > Thanks, > > Andrew > > Instead of vbcrlf use Environment.NewLine > -- > Bits.Bytes > http://bytes.thinkersroom.com "Rad [Visual C# MVP]" <nospam@nospam.com> schrieb: Yes and no. If you want to use a system-specific newline character >> Is it possible to embed a newline constant in a string in the same way >> as c#? I really don't want to do something like this: >> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) >> when I should be able to do >> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) >> >> Not the best example, I am sure, but it does get worse in many cases? >> So, is there a way to do this in vb, or am I stuck? I have tried >> googling but I can't find anything. > > Instead of vbcrlf use Environment.NewLine sequence, use 'Environment.NewLine', otherwise use an appropriate constant in 'ControlChars' to enable the compiler to perform the concatenation at compile time. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Unfortunately, VB does not have a feature comparable to the verbatim string
literals of C#. You are stuck with the syntax you mentioned. -- Show quoteHide quoteDavid Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter Instant Python: VB to Python converter "Andrew Backer" wrote: > Is it possible to embed a newline constant in a string in the same way > as c#? I really don't want to do something like this: > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > when I should be able to do > ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > > Not the best example, I am sure, but it does get worse in many cases? > So, is there a way to do this in vb, or am I stuck? I have tried > googling but I can't find anything. > > Thanks, > Andrew > > David,
Unfortuataly?. I wished that legacy from even before C was not in C#. Cor Show quoteHide quote "David Anton" <DavidAn***@discussions.microsoft.com> schreef in bericht news:C4BAC573-32A4-48C1-ACC9-4C0D999AD6A4@microsoft.com... > Unfortunately, VB does not have a feature comparable to the verbatim > string > literals of C#. You are stuck with the syntax you mentioned. > -- > David Anton > www.tangiblesoftwaresolutions.com > Instant C#: VB to C# converter > Instant VB: C# to VB converter > Instant C++: C#/VB to C++ converter > Instant Python: VB to Python converter > > > "Andrew Backer" wrote: > >> Is it possible to embed a newline constant in a string in the same way >> as c#? I really don't want to do something like this: >> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) >> when I should be able to do >> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) >> >> Not the best example, I am sure, but it does get worse in many cases? >> So, is there a way to do this in vb, or am I stuck? I have tried >> googling but I can't find anything. >> >> Thanks, >> Andrew >> >> Really? I find it is a very intuitive wysiwyg feature.
string myString = @"this string extends over many lines and has line breaks exactly as you see them here"; -- Show quoteHide quoteDavid Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter Instant Python: VB to Python converter "Cor Ligthert [MVP]" wrote: > David, > > Unfortuataly?. > > I wished that legacy from even before C was not in C#. > > Cor > > "David Anton" <DavidAn***@discussions.microsoft.com> schreef in bericht > news:C4BAC573-32A4-48C1-ACC9-4C0D999AD6A4@microsoft.com... > > Unfortunately, VB does not have a feature comparable to the verbatim > > string > > literals of C#. You are stuck with the syntax you mentioned. > > -- > > David Anton > > www.tangiblesoftwaresolutions.com > > Instant C#: VB to C# converter > > Instant VB: C# to VB converter > > Instant C++: C#/VB to C++ converter > > Instant Python: VB to Python converter > > > > > > "Andrew Backer" wrote: > > > >> Is it possible to embed a newline constant in a string in the same way > >> as c#? I really don't want to do something like this: > >> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > >> when I should be able to do > >> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > >> > >> Not the best example, I am sure, but it does get worse in many cases? > >> So, is there a way to do this in vb, or am I stuck? I have tried > >> googling but I can't find anything. > >> > >> Thanks, > >> Andrew > >> > >> > > > David Anton wrote:
> Really? I find it is a very intuitive wysiwyg feature. Which is fine for 'C'-like languages, where the end of statement marker > > string myString = @"this > string extends over many lines and > has line breaks exactly as you see them here"; is an explicit ";", but not so well in VB, where end-of-line = end-of-statement. :-) Regards, Phill W. Right - I can see why it's not done in VB, but the reason is purely
technical, not because anyone should find it confusing. -- Show quoteHide quoteDavid Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C#/VB to C++ converter Instant Python: VB to Python converter "Phill W." wrote: > David Anton wrote: > > Really? I find it is a very intuitive wysiwyg feature. > > > > string myString = @"this > > string extends over many lines and > > has line breaks exactly as you see them here"; > > Which is fine for 'C'-like languages, where the end of statement marker > is an explicit ";", but not so well in VB, where end-of-line = > end-of-statement. :-) > > Regards, > Phill W. > "David Anton" <DavidAn***@discussions.microsoft.com> schrieb: It's not even technical. It would be possible to extend the compiler to > Right - I can see why it's not done in VB, but the reason is purely > technical, not because anyone should find it confusing. support "continued" string literals. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Phil,
I agree, and know the annoyances that come with doing this kind of escaping in C/etc. For fun I want you to try it in TSQL where you have to use quotes, and then you need to embed other calls that also use quotes. This is real issue where the procedure compiler won't let you use variables for the parameter to openrowset(), so you embed and embed and end up with 8 quotes in a row. It'll put hair on your chest an take it off your head. C# semi-fixed this with the @"c:\no\escape\chars\here" format, which is really quite handy. I don't expect VB to do anything exactly like this, or even do it by default. It is technically (as H said) possible to do this, but I didn't know if it had been done. Perhaps there was a way (and I tried this) to prefix the string with @ so that @"in vb this \n is now a newline" would work. It was just a dream :) Back to the old ampersands, or pluses, I never can remember which. //Andrew Herfried K. Wagner [MVP] wrote: Show quoteHide quote > "David Anton" <DavidAn***@discussions.microsoft.com> schrieb: > > Right - I can see why it's not done in VB, but the reason is purely > > technical, not because anyone should find it confusing. > > It's not even technical. It would be possible to extend the compiler to > support "continued" string literals. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Andrew Backer wrote:
> Is it possible to embed a newline constant in a string in the same way The only way I can think of is:> as c#? I really don't want to do something like this: > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > when I should be able to do > ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > > Not the best example, I am sure, but it does get worse in many cases? > So, is there a way to do this in vb, or am I stuck? I have tried > googling but I can't find anything. > > Thanks, > Andrew String.Format("Line 1 : {0}{1}Line2 : {2}", o, vbcrlf, t) za***@construction-imaging.com wrote:
Show quoteHide quote > Andrew Backer wrote: I was hoping that wouldn't be the answer ;) Why add so much extra stuff> > Is it possible to embed a newline constant in a string in the same way > > as c#? I really don't want to do something like this: > > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > > when I should be able to do > > ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > > > > Not the best example, I am sure, but it does get worse in many cases? > > So, is there a way to do this in vb, or am I stuck? I have tried > > googling but I can't find anything. > > > > Thanks, > > Andrew > > The only way I can think of is: > > String.Format("Line 1 : {0}{1}Line2 : {2}", o, vbcrlf, t) to the language but the leave off this kind of nicety? "Andrew Backer" <awbac***@gmail.com> wrote in message Aren't you supposed to use a string builder for such tasks?news:1165432302.604369.227830@79g2000cws.googlegroups.com... > I was hoping that wouldn't be the answer ;) Why add so much extra stuff > to the language but the leave off this kind of nicety? Homer J Simpson wrote:
> "Andrew Backer" <awbac***@gmail.com> wrote in message Um, sure. Just ignore the code I wrote, and in any case that was not> news:1165432302.604369.227830@79g2000cws.googlegroups.com... > > > I was hoping that wouldn't be the answer ;) Why add so much extra stuff > > to the language but the leave off this kind of nicety? > > Aren't you supposed to use a string builder for such tasks? the question. Is embedding a control character possible, in some way, as in c#? Also, look to stringbuilder vs. string performance for single use, small cases. // Andrew You might be taken more seriously if you used your name. Andrew Backer wrote:
> za***@construction-imaging.com wrote: But if you added the "nicety" of "\n", you suddenly have to deal with >> Andrew Backer wrote: >>> Is it possible to embed a newline constant in a string in the same way >>> as c#? I really don't want to do something like this: >>> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) >>> when I should be able to do >>> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) >>> > I was hoping that wouldn't be the answer ;) Why add so much extra stuff > to the language but the leave off this kind of nicety? all the mucking about that "\\" and all the other escape sequences entail. Suddenly, all your [UNC] paths to files becomes aPITA: sPath = "\\\\server\\share\\dir\\dir\\file.ext" Or would we need some "escaping" character that tells VB we're using this sort of this "C String"? How about a leading '@' sign? sPath = @"\\\\server\\share\\dir1\\dir2\\file.ext" sPath = "\\server\share\dir1\dir2\file.ext" Oh, but that would confuse the C# programmers. We'd have to do it the other way around and, in doing so, break every string literal we've ever coded... :-( Maybe Our Friends in Redmond will give us a CString class in the next Framework (or, at least make String inheritable!)... ;-) Regards, Phill W. <za***@construction-imaging.com> schrieb:
>> Is it possible to embed a newline constant in a string in the same way This solution is even worse because one additional concatenation needs to be >> as c#? I really don't want to do something like this: >> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) >> when I should be able to do >> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) >> >> Not the best example, I am sure, but it does get worse in many cases? >> So, is there a way to do this in vb, or am I stuck? I have tried >> googling but I can't find anything. > > The only way I can think of is: > > String.Format("Line 1 : {0}{1}Line2 : {2}", o, vbcrlf, t) performed at runtime! -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Herfried K. Wagner [MVP] wrote:
Show quoteHide quote > <za***@construction-imaging.com> schrieb: I agree, I was just trying to show the OP the futility in his request.> >> Is it possible to embed a newline constant in a string in the same way > >> as c#? I really don't want to do something like this: > >> ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) > >> when I should be able to do > >> ++ String.Format("Line 1 : {0}\nLine2 : {2}", o, t) > >> > >> Not the best example, I am sure, but it does get worse in many cases? > >> So, is there a way to do this in vb, or am I stuck? I have tried > >> googling but I can't find anything. > > > > The only way I can think of is: > > > > String.Format("Line 1 : {0}{1}Line2 : {2}", o, vbcrlf, t) > > This solution is even worse because one additional concatenation needs to be > performed at runtime! > Sorry I am futile, but in reality this is just a simple Yes (and here> I agree, I was just trying to show the OP the futility in his request. is how) or No question. It got answered a while back that it is probably not possible. To explain my frustration I will do this again : In c++/c/c#/php/just about everything you can embed control chars in astring using a \. Examples of this include, but are not limited to, \n \r \t. An example : "This is the first line \n and this is the second \n\t and this is tabbed in" *** My question was, and still is, this : Can I do this in VB.Net somehow. That is all. ---------------------------- In response I have gotten a lot of OT and other comments that really don't answer the actual question. I know it is difficult to read the OP, but even with performance in mind I am not sure how relevant the remarks are. I will take the hit of an extra concatenation for easier to read code. Perhaps if this were in a loop of 10K + allocations I might ask a question and phrase it as such : "What is the fastest way to so xxxx". In this case, unless this is seriously the choke point in my application and I am sure the rest of the damn framework is perfectly optimized for this (And I am sure all the perf guys have analyzed the IL) then I'll worry about the extra cycle. But it wouldn't matter because it's just in an exception formatter, and is rarely called. I know, I didn't say where it was. But that's because it wasn't the question. Okay, this is what everybody meant: No.
;-) Robin S. ------------------------------------- Show quoteHide quote "Andrew Backer" <awbac***@gmail.com> wrote in message news:1165443983.886094.174140@l12g2000cwl.googlegroups.com... > > >> I agree, I was just trying to show the OP the futility in his request. > > Sorry I am futile, but in reality this is just a simple Yes (and here > is how) or No question. It got answered a while back that it is > probably not possible. To explain my frustration I will do this again > : > > In c++/c/c#/php/just about everything you can embed control chars in a > string using a \. > > Examples of this include, but are not limited to, \n \r \t. > An example : "This is the first line \n and this is the second \n\t and > this is tabbed in" > > *** My question was, and still is, this : > Can I do this in VB.Net somehow. That is all. > > ---------------------------- > > In response I have gotten a lot of OT and other comments that really > don't answer the actual question. I know it is difficult to read the > OP, but even with performance in mind I am not sure how relevant the > remarks are. I will take the hit of an extra concatenation for easier > to read code. > > Perhaps if this were in a loop of 10K + allocations I might ask a > question and phrase it as such : "What is the fastest way to so xxxx". > In this case, unless this is seriously the choke point in my > application and I am sure the rest of the damn framework is perfectly > optimized for this (And I am sure all the perf guys have analyzed the > IL) then I'll worry about the extra cycle. But it wouldn't matter > because it's just in an exception formatter, and is rarely called. I > know, I didn't say where it was. But that's because it wasn't the > question. > Andrew Backer wrote:
<snip> > In c++/c/c#/php/just about everything you can embed control chars in a <snip>> string using a \. > > Examples of this include, but are not limited to, \n \r \t. > An example : "This is the first line \n and this is the second \n\t and > this is tabbed in" > > *** My question was, and still is, this : > Can I do this in VB.Net somehow. That is all. No, unfortunatelly it's not possible. Just as it isn't possible to have multi-line strings, multi-line comments and multiple results from a function... =P B. "Andrew Backer" <awbac***@gmail.com> schrieb: What's the problem? The code is functionally completely equivalent to the > Is it possible to embed a newline constant in a string in the same way > as c#? I really don't want to do something like this: > ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t) C# code if "\r\n" is embedded into the literal in the source code. Note that the concatenation can be performed by the compiler because 'vbCrLf' is a constant! -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
OLEDBCommand vs. SQLCommand
cUpdate Custom attribut with reflection MDI Parent Forms Exe Size Re: Which do you prefer? XML File into a SQL table how pass Date vaiable to XPath query DLL returns a variant data type - how to convert and use in VB .NET Setting Tab Index between Panels Filecopy sourcefile |
|||||||||||||||||||||||