473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Equivalent of _ used in VB as concatenating code statement

Hi I want to construct a long string in C# in multiple lines therefore I
need a symbol to concatenate each line to the next line till the end of the
string.

In VB, there's a symbol "_" can be used at the end of each line. So what is
the equivalent in C#?

I don't like use "+" to separate a long string into multiple short ones
since it incurrs more double quotes.

Thanks in advance

-Richard
Nov 15 '05 #1
5 4647
Richard Chen wrote:
In VB, there's a symbol "_" can be used at the end of each line.
That's for long lines of code, not long strings.
So what is the equivalent in C#?
There is no counterpart since a line doesn't end until a smicolon is
encountered. Just press Enter.
I don't like use "+" to separate a long string into multiple short
ones since it incurrs more double quotes.


You have no choice as a string cannot include a hard return unless it's
a character (i.e. "\n").

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
Well, the only way I know of is using + which has the same meaning for
separate parts of a string or separate parts of any other stuff. Remember
a command is terminated with ; in C# so it can span many lines.

String line = "blah blah "
+ "some more blah "
+ Int32.Parse("1")
+ "\n";

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3
And of course, you COULD always use a StringBuilder

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr0bth7lkhntkfz@localhost...
Well, the only way I know of is using + which has the same meaning for
separate parts of a string or separate parts of any other stuff. Remember
a command is terminated with ; in C# so it can span many lines.

String line = "blah blah "
+ "some more blah "
+ Int32.Parse("1")
+ "\n";

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Frank Oquendo <fr****@acadxpin.com> wrote:
I don't like use "+" to separate a long string into multiple short
ones since it incurrs more double quotes.


You have no choice as a string cannot include a hard return unless it's
a character (i.e. "\n").


Not quite - if you are happy for the string itself to include the
return, you can use verbatim literals:

using System;

public class Test
{
static void Main(string[] args)
{
string x = @"hello
there";
Console.WriteLine (x);
}
}

I don't think I'd really recommend it though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Thanks! That's what I want!

Thanks for all the other posts!

Cheers/Richard
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Frank Oquendo <fr****@acadxpin.com> wrote:
I don't like use "+" to separate a long string into multiple short
ones since it incurrs more double quotes.


You have no choice as a string cannot include a hard return unless it's
a character (i.e. "\n").


Not quite - if you are happy for the string itself to include the
return, you can use verbatim literals:

using System;

public class Test
{
static void Main(string[] args)
{
string x = @"hello
there";
Console.WriteLine (x);
}
}

I don't think I'd really recommend it though...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gregory W. Ernest | last post by:
I am new to Java programming and I was wondering if anyone can tell me the java equivalent to a cin>>...; that is normally used in c++. I want to get user input and automatically assign it to a...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
4
by: Scott Johnson | last post by:
Hi I am converting some code from C# to VB.NET and I have come across a command that I can't find the VB equivalent. The C# command is 'lock' and I think it is used to lock a data type from...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
6
by: Jon Paal | last post by:
what is vb equiv. of ++ shown in C# ?
21
by: clintonG | last post by:
Will somebody convert this for me... System.Web.UI.HtmlControls.HtmlHead header; header = TryCast(this.Page.Header, System.Web.UI.HtmlControls.HtmlHead); <%= Clinton Gallagher NET csgallagher...
7
by: Mary | last post by:
I have a student who has a hyphenated first name. If I concatenate the name like this: StudentName:( & ", " & ), it works as expected. If, however, I try to get the first name first by...
10
by: Neil | last post by:
Using the MS Rich Textbox Control 6.0 in Access 2000, I need to concatenate several RTB controls into a single RTF file. Sometimes two strings will be side-by-side; other times they need to be...
4
by: laurenquantrell | last post by:
Is there an equivalant construction to the CASE WHEN statement that can be used in the WHERE clause? For example, this works: SELECT FirstName = CASE WHEN c.FirstName = 'Bob' THEN 'Robert'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.