Showing posts with label newline. Show all posts
Showing posts with label newline. Show all posts

Thursday, March 22, 2012

Newline Characters

I added a newline to a string using: ControlChars.NewLine

I want to convert all those newlines to "<br>"

i tried:


Replace(myString, cStr(ControlChars.NewLine) , "<br>")

but it had no effect at all. any ideas?I think it is the other way around:


Replace(myString, "<br>", cStr(ControlChars.NewLine))

If you're using VB, don't you have access to the vbCrLf constant? If so you might be able to do

Replace(myString, vbCrLf, "<br>")

or

Replace(myString, Chr(13), "<br>")
Hello,

i always replace my newline with the help ofRegular Expression code like in the following example...

// Remove the newline's and replace them with <br /> tag
Regex inRegex;
inRegex = new Regex("\n", RegexOptions.IgnoreCase);
lblTest.Text = inRegex.Replace(sText, "<br />");
This sample is written in C# but it should be easy to translate to vb.net. If you need further help please post again...

HTH,
thanks guys,

it worked! btw, what does vbcrlf stand for?
vbcrlf --> I believe it is "VisualBasic CarriageReturn and Line Feed"
Or you can use Environment.NewLine no matter what language you are using.

newline character - easy question

A Stupidly easy question - what is the newline character for VB.NET?

I have tried:
label.text = "first line \n second line"
and it doesnt work.

JagsYou could use VBCrlf or Environment.NewLine
If you want value in labe to come in next line then you have to use

"first line <br> second line"

[VBCrlf or NewLine dosn't work in HTML. So you have to use <br>]

hope it helps!
The VBCrlf was the one I wanted. Just wondering if I could put that into a sctring, i.e. instead of writing

label.text = "The is the first " & VBCrlf & "This is the second"

I could write something like

label.text = "This is the first \VBCrlf This is the second"
You can't do as below

label.text = "This is the first \VBCrlf This is the second" as it treates as a word in the string!

Friday, March 16, 2012

newline at Label.Text -- ??

hi,

i have a problem...i have a textBox with multiline enabled, where a user writes a description (some text)

if you press Enter, a new line appears and you may write on multilines, and when i save the description in my database, in place of "newline" i have two squares (i should copy-paste them here but they are interprated as a newline:P - ENTER)

When i load the description from the database into a textbox, the sqares have no effect because there should be a "<br>" or a html command for new line.

what should i do, to save direct in my database the <br> in place of that squares (witch apears when you press enter on a multiline textbox)?

i tryiedLabel1.Text.Replace(" ","<br>"); but i can't paste the squares at first arrgument, because it apears at a new line

i hope you understand...

please help me, thanks

How about:

Label1.Text.Replace(Environment.NewLine,"<br />");


Very good, thank you

Newline detected when add script in C# (ASP.NET)

Hi!

I'm trying to add script to the page and place following code in my ascx
(control):

Page.RegisterClientScriptBlock("adder", "<script>function
doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
eval(document.all.TextBox2.value)}</script>");

It doesn't work giving me all kind of problems...

I suspect the problem is with <> charachters.

How do I go around this problem?

Also, placing this line in code (I use WebMatrix) will mess up all HTML
code??

Thanks!If that is the exact line from your code, then it just has to do with how
your formed your string. You cannot insert a line break in a string in C#.
It should work if you change your code to read:

Page.RegisterClientScriptBlock("adder", "<script>function " +
"doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
" +
"eval(document.all.TextBox2.value)}</script>");

or, for more readability, I always for my javascript in a temp variable
first. Just kinda hard to read otherwise

string script = "<script>function " +
"doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
" +
"eval(document.all.TextBox2.value)}</script>"
Page.RegisterClientScriptBlock("adder", script);

either way, both of those should work for you.

-Cliff

"Ivan Demkovitch" <i@.a.b> wrote in message
news:OfydJF8oDHA.976@.tk2msftngp13.phx.gbl...
> Hi!
> I'm trying to add script to the page and place following code in my ascx
> (control):
>
> Page.RegisterClientScriptBlock("adder", "<script>function
> doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
> eval(document.all.TextBox2.value)}</script>");
> It doesn't work giving me all kind of problems...
> I suspect the problem is with <> charachters.
> How do I go around this problem?
> Also, placing this line in code (I use WebMatrix) will mess up all HTML
> code??
> Thanks!
I solved problem...

Actually the problem was in "</script>"

Changed to "<" + "/" + "script>" and it works fine now.

Thanks!

"Cliff Harris" <hersh@.myrealbox.com> wrote in message
news:OkD03L8oDHA.644@.TK2MSFTNGP11.phx.gbl...
> If that is the exact line from your code, then it just has to do with how
> your formed your string. You cannot insert a line break in a string in
C#.
> It should work if you change your code to read:
> Page.RegisterClientScriptBlock("adder", "<script>function " +
> "doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value)
+
> " +
> "eval(document.all.TextBox2.value)}</script>");
> or, for more readability, I always for my javascript in a temp variable
> first. Just kinda hard to read otherwise
> string script = "<script>function " +
> "doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value)
+
> " +
> "eval(document.all.TextBox2.value)}</script>"
> Page.RegisterClientScriptBlock("adder", script);
> either way, both of those should work for you.
> -Cliff
>
> "Ivan Demkovitch" <i@.a.b> wrote in message
> news:OfydJF8oDHA.976@.tk2msftngp13.phx.gbl...
> > Hi!
> > I'm trying to add script to the page and place following code in my ascx
> > (control):
> > Page.RegisterClientScriptBlock("adder", "<script>function
> > doadd(){document.all.TextBox3.value=eval(document. all.TextBox1.value) +
> > eval(document.all.TextBox2.value)}</script>");
> > It doesn't work giving me all kind of problems...
> > I suspect the problem is with <> charachters.
> > How do I go around this problem?
> > Also, placing this line in code (I use WebMatrix) will mess up all HTML
> > code??
> > Thanks!

Newline in a multiline-textbox filled by a DataList?

I'm binding my Data to the Datalist like that:

// Opening standard XML text reader
System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(Server.MapPath("~/xml/guestbook.xml"));
DataSet myDataSet = new DataSet();
// Reading XML into a dataset
myDataSet.ReadXml(myXmlReader);
myXmlReader.Close();

// Bind data to the data list!
GuestbookData.DataSource = myDataSet.Tables[0];
GuestbookData.DataBind();

then I read it out like that:

<div class="author"><a href="http://links.10026.com/?link=http://<%# DataBinder.Eval(Container.DataItem, "url") %>" target="_blank"><%# DataBinder.Eval(Container.DataItem, "name") %></a> schrieb am <%# DataBinder.Eval(Container.DataItem, "date") %> </div>
<div class="text"><%# DataBinder.Eval(Container.DataItem, "entry_Text") %></div>

Now I'd like to translate NewLines a User made when he was writing a comment into <br>s because right now, such a text:

writing something

and something else

is shown as writing something and something else. (In just one line without the linebreak).

How to translate those breaks? Thanks!

Change:
<div class="text"><%# DataBinder.Eval(Container.DataItem, "entry_Text") %></div>
to:
<div class="text"><%# ReplaceCRLF(DataBinder.Eval(Container.DataItem, "entry_Text")) %></div>
and then have a function in your page called ReplaceCRLF:
string ReplaceCRLF(string val)
{
return val.Replace(System.Environment.NewLine, "<br/>");
}
-Brock

Thanks, that's working!

newline in constant error

Hi,

I've been getting this error for a long time and haven't been able to figure it out. Up until now I've been doing workarounds to avoid this type of error, but I want to figure out how to fix it without the workarounds.

The error is:
CS1010: Newline in constant

And this is the code:

string scriptString = "<script language=\"JavaScript\" src=\"";
scriptString += appPath + "/js/popupmenu.js\"></script>";

The thing I really don't get is that if I put this exact same code in a cs file it compiles, but if I put it between script tags in an aspx file the error occurs...Hm, I found the answer for anyone who's interested:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;827420

However, why is this behavior by design? Shouldn't the error message be more specific if you're not supposed to put </script> in a string?

Thanks to anyone if they replied before this message gets approved.
Can you show us the full error (including the 5 lines of code that it shows)? There might be more to it.

newline in an email

i need to insert a newline in my email's body but didn't work. I tried borth "\r\n" and Environment.Newine

This is my code:

email_body = "???? ??? ???? ??? ??? ???????";
email_body += Environment.NewLine + Environment.NewLine;
email_body += "??? ????? ??????? ?????? ?????? ?? ??????? ???? ??? ????. ??? ??? ?? ???? ????? ?? ????? ?? ?????? ?????? ???? ??????? ???.";
email_body += "\n\r";
email_body += "????? ??????: " + sql_reader["member_cpr"];
email_body += "\n\r";
email_body += "???? ????: " + sql_reader["member_password"];

If the E-Mail is in HTML format, you can use <br /> as an HTML Break.

newline within a string

How can I insert a new line character (\n?) within a string in C#, so that when I display the string in some text box the string is displayed in multiple linesHi,

you can use System.Envirnment.NewLine() method to insert newline. Also if you are using Multiline textbox then I think you need to do something like this:


string AllText = TextBox1.Text.Replace(System.Envirnment.NewLine(),"<BR>");


What I am trying to do is

string strnewline;
TextBox1.text=strnewline;

Now I want to define the strnewline such that
TextBox1.text=strnewline;

displays the text in multiple lines. TextBox1 is multilined.

In short, is there any alternative to C-lang "/n " ?
check the code that I gave you it works !!!!

Newline with HTMLEncode in Div and Label

Hi

I have a table column that has multiple lines (\r\n) and html tags in it. I
want to display it in a div and label that html tags can be seen and
newlines should work.
If i use div.innerHTML newlines are lost and html tags doesn't show.
If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks works
but html tags doesn't show.
If i use div.innerText again newlines and html tags are lost.

What can i do?

ThanksVersus,
The bottom line is that "\r\n" means nothing in HTML - you have to change it
to "<br/>" -- which means you need to pre-process your string with
..Replace("\r\n", "<br/>");

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"versus" wrote:

Quote:

Originally Posted by

Hi
>
I have a table column that has multiple lines (\r\n) and html tags in it. I
want to display it in a div and label that html tags can be seen and
newlines should work.
If i use div.innerHTML newlines are lost and html tags doesn't show.
If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks works
but html tags doesn't show.
If i use div.innerText again newlines and html tags are lost.
>
What can i do?
>
Thanks
>
>
>


Thanks for answering. Replace(Environment.NewLine,"<br>") already works for
that problem. But i cannot see html tags as regular text. I want them to be
displayed not parsed with htmlparser.

Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines and
html tags to be displayed at the same time.

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yohohhoandabottleofrum.comwrote
in message news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

Versus,
The bottom line is that "\r\n" means nothing in HTML - you have to change
it
to "<br/>" -- which means you need to pre-process your string with
.Replace("\r\n", "<br/>");
>
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
>
>
>
"versus" wrote:
>

Quote:

Originally Posted by

>Hi
>>
>I have a table column that has multiple lines (\r\n) and html tags in it.
>I
>want to display it in a div and label that html tags can be seen and
>newlines should work.
>If i use div.innerHTML newlines are lost and html tags doesn't show.
>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>works
>but html tags doesn't show.
>If i use div.innerText again newlines and html tags are lost.
>>
>What can i do?
>>
>Thanks
>>
>>
>>


"versus" <tencere@.dibin.karawrote in message
news:ee99xTJGIHA.4808@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Thanks for answering. Replace(Environment.NewLine,"<br>") already works
for that problem. But i cannot see html tags as regular text. I want them
to be displayed not parsed with htmlparser.
>
Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines
and html tags to be displayed at the same time.
>
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.yohohhoandabottleofrum.com>
wrote in message
news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

>Versus,
>The bottom line is that "\r\n" means nothing in HTML - you have to change
>it
>to "<br/>" -- which means you need to pre-process your string with
>.Replace("\r\n", "<br/>");
>>
>-- Peter
>Recursion: see Recursion
>site: http://www.eggheadcafe.com
>unBlog: http://petesbloggerama.blogspot.com
>BlogMetaFinder: http://www.blogmetafinder.com
>>
>>
>>
>"versus" wrote:
>>

Quote:

Originally Posted by

>>Hi
>>>
>>I have a table column that has multiple lines (\r\n) and html tags in
>>it. I
>>want to display it in a div and label that html tags can be seen and
>>newlines should work.
>>If i use div.innerHTML newlines are lost and html tags doesn't show.
>>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>>works
>>but html tags doesn't show.
>>If i use div.innerText again newlines and html tags are lost.
>>>
>>What can i do?
>>>
>>Thanks
>>>
>>>
>>>


>
>


I think if you use the <pretag to wrap your code it will honor the CRLF
and show the tags as if they are text within the <pre></pretags.

Hope this helps
LS
I think if you use the <pretag to wrap your code it will honor the CRLF

Quote:

Originally Posted by

and show the tags as if they are text within the <pre></pretags.
>
Hope this helps
LS


Thanks but his solution removes css classes and when i use checkbox with
label, label click doesn't work.
On Sat, 27 Oct 2007 04:55:00 -0700, Peter Bromberg [C# MVP]
<pbromberg@.yahoo.yohohhoandabottleofrum.comwrote:

Quote:

Originally Posted by

>Versus,
>The bottom line is that "\r\n" means nothing in HTML - you have to change it
>to "<br/>" -- which means you need to pre-process your string with
>.Replace("\r\n", "<br/>");
>
>-- Peter
>Recursion: see Recursion
>site: http://www.eggheadcafe.com
>unBlog: http://petesbloggerama.blogspot.com
>BlogMetaFinder: http://www.blogmetafinder.com


Actually, newlines may make a lot of sense when you want your HTML to
be easily understood if you do a view source on the html page ...

--
http://bytes.thinkersroom.com
On 27 okt, 14:54, "Lloyd Sheen" <a...@.b.cwrote:

Quote:

Originally Posted by

"versus" <tenc...@.dibin.karawrote in message
>
news:ee99xTJGIHA.4808@.TK2MSFTNGP05.phx.gbl...
>

Quote:

Originally Posted by

Thanks for answering. Replace(Environment.NewLine,"<br>") already works
for that problem. But i cannot see html tags as regular text. I want them
to be displayed not parsed with htmlparser.


>

Quote:

Originally Posted by

Let me explain again. I have an sql db table with columns that has both
environment.newline(\r\n) and html tags. I want newlines to break lines
and html tags to be displayed at the same time.


>

Quote:

Originally Posted by

"Peter Bromberg [C# MVP]" <pbromb...@.yahoo.yohohhoandabottleofrum.com>
wrote in message
news:4CA1F3DF-BB2B-479B-8025-69154C4984C5@.microsoft.com...

Quote:

Originally Posted by

Versus,
The bottom line is that "\r\n" means nothing in HTML - you have to change
it
to "<br/>" -- which means you need to pre-process your string with
.Replace("\r\n", "<br/>");


>

Quote:

Originally Posted by

Quote:

Originally Posted by

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"versus" wrote:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>Hi


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>I have a table column that has multiple lines (\r\n) and html tags in
>it. I
>want to display it in a div and label that html tags can be seen and
>newlines should work.
>If i use div.innerHTML newlines are lost and html tags doesn't show.
>If i use div.innerHTML with replace(Environment.NewLine,"<br>") breaks
>works
>but html tags doesn't show.
>If i use div.innerText again newlines and html tags are lost.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>What can i do?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>Thanks


>
I think if you use the <pretag to wrap your code it will honor the CRLF
and show the tags as if they are text within the <pre></pretags.
>
Hope this helps
LS


That's correct but the problem lies elsewhere.
If you update a <pretag with innerHTML, Internet Explorer will
remove the \n's before it's in the <pretag.

newline using itexsharp

how can i add a newline using itexsharp to a pdf document

Hi,

Based on my understanding, you want to add the text to an existed pdf file with itexsharp. If I have misunderstood you, please feel free to let me know.

We can use the itexsharp to read the pdf and write the text to this pdf file. For more information, seehttp://asp-net-whidbey.blogspot.com/2006/04/generating-pdf-files-with-itextsharp.html.

Besides, you can find more information about itexsharp by thehttp://itextsharp.sourceforge.net/. I believe that the best answer to this question is to contacthttp://sourceforge.net/mailarchive/forum.php?max_rows=25&style=ultimate&offset=25&forum_name=itextsharp-questions.

I hope this helps.


I have gone through, such tutotrials

i have tried to adda newline

mydfDocument.add("\n")

but this did not worked