473,385 Members | 1,798 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.

How to assign a block of text to a string in C#

I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?
Nov 16 '05 #1
5 4974
string x =
@"
some
text
";

If you need to embed quote marks, then double them up using ""
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message
news:7e*************************@posting.google.co m...
I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?

Nov 16 '05 #2
No, there is no equivalent syntax in C#.

--Bob

"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message
news:7e*************************@posting.google.co m...
I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?

Nov 16 '05 #3
The StringBuilder Class [1] is the only practical class offering the
functionality you need to achieve the objective.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/de...classtopic.asp


"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message
news:7e*************************@posting.google.co m...
I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?

Nov 16 '05 #4
I am not sure if this is exactly correct but try.

string myString = null;
TextReader tr = File.OpenText(@"C:\test\sometext.txt");
myString = tr.ReadToEnd();
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:<uH**************@TK2MSFTNGP11.phx.gbl>...
The StringBuilder Class [1] is the only practical class offering the
functionality you need to achieve the objective.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1]
http://msdn.microsoft.com/library/de...classtopic.asp


"Richard Frenkel" <ne*******@frenkelfamily.org> wrote in message
news:7e*************************@posting.google.co m...
I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?

Nov 16 '05 #5
One idiea that I've had that haven't followed up on is to have an imbedded
text file. Then just read the text file when needed. I know there's a way.
Also if it comes down to it you could right a very basic program that auto
wrote all those "x += " for you. Just two textboxes. Probably not what
you're wanting though.

On 08/05/2004 ne*******@frenkelfamily.org (Richard Frenkel) wrote:
I'd like to embed a bunch of text in a c# source file and assign it to
a string.
something like:

----------------------------
string x = <<eof

This is a bunch of text
that is assigned to string x
until the "eof" on a line
by itself is encountered.

eof
-------------------------------

of course anyone using Perl will recongize this very convenient
syntax. Otherwise one has to go thru:

x = 'blah blah';
x += 'more blah blah";
etc which is tedious. Just adding all the quotes is tedious. And if
there are quotes in the text block it's even MORE tedious, and tedium
is something I don't care for as a programer. So is there a way to do
this in the C# compiler?

Nov 16 '05 #6

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

Similar topics

9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
0
by: Richard Frenkel | last post by:
Thanks for the feedback! There were a number of good ideas, but the easiest is Justins (which I've tested). This works: string x = @" some text
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
2
by: Przemek | last post by:
Hi, I'm trying to parse some text file, which contain blocks of text. First my code: Public Class Parser Public Sub New(ByVal fs As String) Dim sr As StreamReader sr =...
2
by: rachit.goyal | last post by:
Hi All, I am using .net first time.In my windows form VC7 application, on a click of button, I am assigning text of TextBox to STL string varibale. Using this code- private: System::Void...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
9
by: TC | last post by:
Hey All, I posted this to the Crypto users group and forgot to add the VB.Net users group. I apologize for any confusion. I have been testing a try / catch / finally block and purposely...
16
by: HillBilly | last post by:
This is freaking me out. I'm using Membership and trying to determine if the database is online. The GetConnectionString( ) method returns a connection string as expected but not when used in the...
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: 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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.