Working With Static Chunks Of Text

Hi,
I’m wondering what the easiest way would be to work with (i.e. return to the end user in some format) a large chunk of text.

It may be a silly question, but here’s the scenario:

I’ve got some css code that I want to return to the user, and I’d like to return it to them with the line breaks and tabs that already exist rather than giving it all in 1 line.

I also don’t want to manually insert vbcrlf and vbtab.

I’ve tried sticking the code in text files within visual basic but I think it would be a little cumbersome to retrieve it.

Basically I’d like to do the following:


if a=b then

dim test1 as string = _
"blah blah blah
blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
    blah blah blah
blah blah blah
blah blah blah
blah blah blah"

else

dim test2 as string = _
"blah blah blah
blah blah blah
    blah blah blah
blah blah blah
blah blah blah
    blah blah blah
blah blah blah
blah blah blah
blah blah blah"
end if

Any suggestions?

Also, SlitheryImp, could you please explain how I could set up your solution, as having a good knowledge of all possibilities would be very handy for me.

Nothing special really, I have a field defined as ntext:
[CSSText] [ntext] NULL

And add a string to it in the usual manner, usually from a TextBox in Code Behind.

Something like this?

Response.Write(@"<pre>lkjwe jf9e
lske
e
e
r
e

tkejlwe
wpoeir
</pre>");

sorry I should have specified that I’m using vb (And it’s a desktop app if that makes a difference).
But otherwise, yes exactly that.

Is there a vb equivalent?

I still need a vb based solution, anyone got any ideas?

Use a Label control, formatted with new-line character:



label1.Text = "How to Format A Windows Forms Label, making it multi-Line: \
 ";
   label1.Text += "   *  This is indented line 1\
 ";
   label1.Text += "   *  This is indented line 2\
 ";
   label1.Text += "   *       A) This is indented line 3\
 ";
   label1.Text += "   *       B) This is indented line 4\
 ";



Correction, didn’t see the VB part :slight_smile:



label1.Text = "How to Format A Windows Label, making it multi-Line:" & vbCrLf
   label1.Text += "   *  This is indented line 1 " & vbCrLf
   label1.Text += "   *  This is indented line 2 " & vbCrLf
   label1.Text += "   *       A) This is indented line 3 " & vbCrLf
   label1.Text += "   *       B) This is indented line 4 " & vbCrLf



But doesn’t that mean that I’m still going to have to write 1 line at a time or use " _" for every line?

I’d like to write 100 lines in 1 go and just put quotations around it or something (Pretty much exactly as your c# code is

Bingo! After every " in each line insert a “_”, then you can add it to the Label1.Text = myString, which would add all of the variable data together (a sentence, i.e.). Plus, if you want to start a new line add, “vbCrLf”.

Okay, so in other words, there is no way in vb to specify a large chunk of text split across several lines with a single variable, without having to add " _" for every line?

I don’t believe you :stuck_out_tongue:

Isn’t there some way to include the contents of a text file or something?
I.e. read a css file line by line, and rebuild the string line by line into a variable.

That would work, but I don’t really know how to include a text file (As it will be installed on an end user’s machine, so I want to keep everything together).

If there is a way to just specify a chunk of text across multiple lines without having to mess around with line continuation characters, that would be preferable, but I’m lead to believe such a feature does not exist :frowning:

Sorry bro, that is the only solution I know, it isn’t pretty, but it gets the job done. Anyone else want to chime in?

You’re going to have to. Since the back slash doesn’t really have the same meaning in VB as it does in C# the string literal really isn’t necessary.

That sounds slow. That may give you a performance hit. I don’t know for sure though.

You can do one page or even a user control in C#, right?

You could also store the text in the database, using the nText DataType

As for the reading from text files, I don’t think the performance hit for my particular use will be noticeable, as it will be less than 100 lines of text.

It’s probably going to be most appropriate but not ideal for me.

How can I include text files with the executable when someone else goes to install it?

As for the text in a database, I don’t think that would really be appropriate, as presumably it wouldn’t take any formatting into account (Such as line break, which is the only formatting I really care about).

So all I need is for someone to help me with the inclusion of text files in a project and how to access them externally (i.e. when someone installs the software, it will have to look in the install location somewhere for these text files), and then I’ll have a solution I can use.

Thanks for all your replies so far.

You can embed the file has a resource, and you are left with only one file. I will try to find a link for embedding resources and reading files.

Resources: http://msdn.microsoft.com/en-us/library/9za7fxc7.aspx
I thnik in VB you can access the a text file as a string from My.Resources
http://msdn.microsoft.com/en-us/library/6wkcc526.aspx

A Text field in the database (or nText) will preserve all formatting (tabs, line breaks etc.), I use it all the time for large chunks of user inputted text.

Okay, if I go in to the solution explorer and add an item (a text file), how can I reference that file in my project? I have a feeling that once I know that I’ll be able to proceed.

pufa I can’t seem to find my included textfile with “my.resources”

Also, SlitheryImp, could you please explain how I could set up your solution, as having a good knowledge of all possibilities would be very handy for me.

Thanks

That code looks alien to me.
Is that vb?
If so, can you explain how I should implement it please?

That’s database lingo. :smiley:
column name/data type/nullable