Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Saturday, March 31, 2012

String Stripping

Hi,

I am trying to create a page that will check user input against a value in database. This page will have a text box for user to enter serial #.
Serial # length is variable but last 3 digit is always number.
For examples:
W04051234-PAY001 in this example code is 1234-PAY
W05051234-PAT002 in this example code is 1234-PAT

A12056040-G001 in this example code is 6040-G
B11056080-SU001 in this example code is 6080-s

Which is the best approach to extract CODE from user input?

Any help will be appriciated.

Thank

TekinUse the Regular Expression class, RegExp with a regular expression that looks for:
4 digits (or is it 3?) followed by
dash
followed by 1 or letters

That expression is:
\d{4}\-[A-Za-z]+
Actually,

I would like to Trancate first 5 digits and last 3 digits.

For examples:
W04051234-PAY001 in this example code is 1234-PAY
If you are attempting to strip a specific group of characters, the String class has numerous useful methods. I encourage you to read about the String class in the .net docs. I think the SubString() and Length() methods will be useful.

String To Decimal

Hi,

How can I convert from string (Text Box) to Decimal (addition some entries then get result)

Thanks,

http://tinyurl.com/aqpgm

To Decimal method.

Please can u write thz method

sorry for disturbing


cavalry wrote:

Please can u write thz method

Scroll down just a little bit on that link above and therz the method in both VB and C#


Hi again,

i see the like but

Access to the requested URL is not allowed!

there is a ristriction to it in my city, so plz copy a paste here

sorry again


thank u its DONE

i've Declare

Dim Grade1 as Double=Grade1.Text

Dim Grade2 as Double=Grade2.Text

Dim Grade as double = Grade1+Grade2

Thanks Alot

string to integer

Hello

I need to do something like this, read data from text file and use it as integer. How can I do it?

Please help me...

Artur

myString = "1234"

myInt = CInt(myString)


Is the text that you are retrieving strictly a number, or is it a combination of text and numbers where you only want to get the numbers? If it's just numbers, you can use Integer.Parse() in VB.NET or int.Parse() in C#.

To read a text file, you use the System.IO namespace. The TextReader Class on MSDN has an example of using a TextReader to get the contents of a text file.

TextReader Class

If the variable m_Text contained the contents of the text file, then here is how you would use Integer.Parse:

VB.NET
Dim m_NumberAs Integer
m_Number =Integer.Parse(m_Text)

C#
int m_Number;
m_Number =int.Parse(m_Text);

HTH


If you are expecting it to be numbers either of the ways above will work however if you try to cast you might want to wrap it in a try to catch any problems in case someone does put in non number data

string.ReadLine

hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value
instead of
"my string" value
how do i keep the value on the same line as my string?
thanks,
rodcharRemove the new-line char before appending.
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:3F4906CE-8C17-4026-83D7-974DEB940147@.microsoft.com...
hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value
instead of
"my string" value
how do i keep the value on the same line as my string?
thanks,
rodchar
Sorry, ignore my reply.
"Siva M" <shiva_sm@.online.excite.com> wrote in message
news:OGy8ypG$GHA.4464@.TK2MSFTNGP02.phx.gbl...
Remove the new-line char before appending.
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:3F4906CE-8C17-4026-83D7-974DEB940147@.microsoft.com...
hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value
instead of
"my string" value
how do i keep the value on the same line as my string?
thanks,
rodchar
Howdy,
Dim reader As StreamReader = File.OpenText(pathToMyFile)
Dim line As String = reader.ReadLine()
Dim builder As New System.Text.StringBuilder()
Do Until line Is Nothing
builder.Append("my value")
builder.Append(line)
line = reader.ReadLine()
Loop
TextBox1.Text = builder.ToString()
Milosz Skalecki
MCAD
"rodchar" wrote:

> hey all,
> i'm trying to read a text document line by line into a stringbuilder and a
n
> issue i'm running into is this:
> do while streamReader.ReadLine
> stringBuilder.Append("my string" & string.ReadLine)
> is showing up like this:
> "my string"
> value
> instead of
> "my string" value
> how do i keep the value on the same line as my string?
> thanks,
> rodchar
thanks for the help. rod.
"Milosz Skalecki" wrote:
> Howdy,
>
> Dim reader As StreamReader = File.OpenText(pathToMyFile)
> Dim line As String = reader.ReadLine()
> Dim builder As New System.Text.StringBuilder()
>
> Do Until line Is Nothing
> builder.Append("my value")
> builder.Append(line)
> line = reader.ReadLine()
> Loop
>
> TextBox1.Text = builder.ToString()
> --
> Milosz Skalecki
> MCAD
>
> "rodchar" wrote:
>

Wednesday, March 28, 2012

String was not recognized as a valid DateTime.

I am capturing a value from a text field and insert it into database of data type DateTime. I have used Convert.ToDateTime("stringdate") to convert it into datetime but i get the above error. But when I converted DateTime value to string and then converted it into DateTime using above method it works fine. I don't know what I need to do.

thanx for any helpIt's likely because the DateTime class can't figure out what date format the string is in. If you use DateTime.Parse that might work or if you always know what format your string is in use DateTime.ParseExact, because with that you can specify the date format.
Try:

FromDate = Convert.ToDateTime(Request.Form["FromDate"].ToString()).Date;

Where FromDate is the txtField - I had trouble with this - Seems like going around the houses a bit to me, but it works.

Pete

String with double quotes

I have a label control on my form. I'm assigning a text to the label at
runtime.
The problem is that the string that I'm trying to assign also contains text
in double quotes.So when I try n assign this to the label I face a problem.
my code is using vb.net

Please help me out in getting this thing done, Is there any in-built
function or property to handle the same?

thanx
GaneshAre you getting any specific error messages?

You may need to encode your string using System.Web.HttpUtilites.HtmlEncode,
before putting it into your label.

Mun

--
Munsifali Rashid
http://www.munit.co.uk/blog/

"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
>I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
> text
> in double quotes.So when I try n assign this to the label I face a
> problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
All you need to do is use "double double" quotes (a term I just made up):

For example:

lblMain.text = """Hello World """

will show on your screen as:

"Hello World"

lblMain.text = """" + "Hello World" + """"

will produce the same result!

Hope this helps you!

Fred

"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
> I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
text
> in double quotes.So when I try n assign this to the label I face a
problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
Your best bet would probably be to HTML-encode the string. e.g.:

someLabel.Text = Server.HtmlEncode(yourString)

This will replace the quotes with " named entity, as well as escaping
other HTML that might potentially cause problems (e.g.: unexpected page
modifications or cross-site scripting).

"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
>I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
> text
> in double quotes.So when I try n assign this to the label I face a
> problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
No I don't get any specific error message.
The problem is that I'm reading this from a source where the text contains
phrases that are mentioned in double quotes.
So i dont know how do I handle this.

"Munsifali Rashid" wrote:

> Are you getting any specific error messages?
> You may need to encode your string using System.Web.HttpUtilites.HtmlEncode,
> before putting it into your label.
> Mun
> --
> Munsifali Rashid
> http://www.munit.co.uk/blog/
>
> "Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
> news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
> >I have a label control on my form. I'm assigning a text to the label at
> > runtime.
> > The problem is that the string that I'm trying to assign also contains
> > text
> > in double quotes.So when I try n assign this to the label I face a
> > problem.
> > my code is using vb.net
> > Please help me out in getting this thing done, Is there any in-built
> > function or property to handle the same?
> > thanx
> > Ganesh
>
Hi Ganesh,

There are two ways to have double quote sign in string:

1) Dim strQuote As String = "text""" ' It shows text"

2) Dim strQuote As String = "text" & Chr(34) ' It also
shows text"

HTH

Elton Wang
elton_wang@.hotmail.com

>--Original Message--
>I have a label control on my form. I'm assigning a text
to the label at
>runtime.
>The problem is that the string that I'm trying to assign
also contains text
>in double quotes.So when I try n assign this to the label
I face a problem.
>my code is using vb.net
>Please help me out in getting this thing done, Is there
any in-built
>function or property to handle the same?
>thanx
>Ganesh
>.

String with double quotes

I have a label control on my form. I'm assigning a text to the label at
runtime.
The problem is that the string that I'm trying to assign also contains text
in double quotes.So when I try n assign this to the label I face a problem.
my code is using vb.net
Please help me out in getting this thing done, Is there any in-built
function or property to handle the same?
thanx
GaneshAre you getting any specific error messages?
You may need to encode your string using System.Web.HttpUtilites.HtmlEncode,
before putting it into your label.
Mun
Munsifali Rashid
http://www.munit.co.uk/blog/
"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
>I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
> text
> in double quotes.So when I try n assign this to the label I face a
> problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
All you need to do is use "double double" quotes (a term I just made up):
For example:
lblMain.text = """Hello World """
will show on your screen as:
"Hello World"
lblMain.text = """" + "Hello World" + """"
will produce the same result!
Hope this helps you!
Fred
"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
> I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
text
> in double quotes.So when I try n assign this to the label I face a
problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
Your best bet would probably be to HTML-encode the string. e.g.:
someLabel.Text = Server.HtmlEncode(yourString)
This will replace the quotes with " named entity, as well as escaping
other HTML that might potentially cause problems (e.g.: unexpected page
modifications or cross-site scripting).
"Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
>I have a label control on my form. I'm assigning a text to the label at
> runtime.
> The problem is that the string that I'm trying to assign also contains
> text
> in double quotes.So when I try n assign this to the label I face a
> problem.
> my code is using vb.net
> Please help me out in getting this thing done, Is there any in-built
> function or property to handle the same?
> thanx
> Ganesh
No I don't get any specific error message.
The problem is that I'm reading this from a source where the text contains
phrases that are mentioned in double quotes.
So i dont know how do I handle this.
"Munsifali Rashid" wrote:

> Are you getting any specific error messages?
> You may need to encode your string using System.Web.HttpUtilites.HtmlEncod
e,
> before putting it into your label.
> Mun
> --
> Munsifali Rashid
> http://www.munit.co.uk/blog/
>
> "Ganesh" <Ganesh@.discussions.microsoft.com> wrote in message
> news:AE4E9B39-B05A-4C1C-BFEC-F8AABE008407@.microsoft.com...
>
>

String. Is this Possible? Still trying to figure this out after 4 hours. Thank You.

Hello,
I am changing the property of a control:
myMenu.Item(0).Item(1).Text = "Something"
What I want is to use the path which value is in a string. Something like:
Dim path As String = ".Item(0).Item(1)."
Now I would to the following:
myMenu & path & Text = "Something"
Of course this doesn't work.
Any ideas?
Thank You,
Miguel

There is no simple solution that will enable that idea to work. Youcould get it to work using a utility method that parses the path string, and then attempts to find the various properties within that string. However, that would be a needlessly slow, complex, and error-prone way to find a control.
Whatever it is that you're trying to achieve, you should perhaps reconsider it. I'm sure you'll come up with a simpler solution.

String.Format("{0:p}" - - Remove that space?

Ok this may be silly but I have to ask. Short of doing this:
protected void Page_Load(object sender, EventArgs e) { Single s = 0.0241F; Literal1.Text = String.Format("{0:p}", s).Replace(" %","%"); }

Is there any other way to remove the space between the number and the % sign?

Just Curious.

I do not think so. If exists, please let me know.

This works:

CultureInfo ci=CultureInfo.CurrentCulture.Clone()

as CultureInfo;

System.Threading.Thread.CurrentThread.CurrentCulture=ci;

ci.NumberFormat.PercentNegativePattern=1;

ci.NumberFormat.PercentPositivePattern=1;

int x=5,y=-5;

Response.Write(String.Format("{0:p} {1:p}",x,y));


Yeah work well. Can that be done in WebConfig?
This thread was great, both with the Replace and Culture methods! Thank you, both.
I would think you could set the culture when the web page loaded. Then in the Web.Config you could set the ci.NumberFormat.PercentPositivePattern=1.

string.ReadLine

hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value

instead of
"my string" value

how do i keep the value on the same line as my string?

thanks,
rodcharRemove the new-line char before appending.

"rodchar" <rodchar@.discussions.microsoft.comwrote in message
news:3F4906CE-8C17-4026-83D7-974DEB940147@.microsoft.com...
hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value

instead of
"my string" value

how do i keep the value on the same line as my string?

thanks,
rodchar
Sorry, ignore my reply.

"Siva M" <shiva_sm@.online.excite.comwrote in message
news:OGy8ypG$GHA.4464@.TK2MSFTNGP02.phx.gbl...
Remove the new-line char before appending.

"rodchar" <rodchar@.discussions.microsoft.comwrote in message
news:3F4906CE-8C17-4026-83D7-974DEB940147@.microsoft.com...
hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value

instead of
"my string" value

how do i keep the value on the same line as my string?

thanks,
rodchar
Howdy,

Dim reader As StreamReader = File.OpenText(pathToMyFile)
Dim line As String = reader.ReadLine()
Dim builder As New System.Text.StringBuilder()

Do Until line Is Nothing

builder.Append("my value")
builder.Append(line)

line = reader.ReadLine()

Loop

TextBox1.Text = builder.ToString()

--
Milosz Skalecki
MCAD

"rodchar" wrote:

Quote:

Originally Posted by

hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value
>
instead of
"my string" value
>
how do i keep the value on the same line as my string?
>
thanks,
rodchar


thanks for the help. rod.

"Milosz Skalecki" wrote:

Quote:

Originally Posted by

Howdy,
>
>
Dim reader As StreamReader = File.OpenText(pathToMyFile)
Dim line As String = reader.ReadLine()
Dim builder As New System.Text.StringBuilder()
>
>
Do Until line Is Nothing
>
builder.Append("my value")
builder.Append(line)
>
line = reader.ReadLine()
>
Loop
>
>
TextBox1.Text = builder.ToString()
>
--
Milosz Skalecki
MCAD
>
>
"rodchar" wrote:
>

Quote:

Originally Posted by

hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value

instead of
"my string" value

how do i keep the value on the same line as my string?

thanks,
rodchar


Np, You're welcome
--
Milosz Skalecki
MCAD

"rodchar" wrote:

Quote:

Originally Posted by

thanks for the help. rod.
>
"Milosz Skalecki" wrote:
>

Quote:

Originally Posted by

Howdy,

Dim reader As StreamReader = File.OpenText(pathToMyFile)
Dim line As String = reader.ReadLine()
Dim builder As New System.Text.StringBuilder()

Do Until line Is Nothing

builder.Append("my value")
builder.Append(line)

line = reader.ReadLine()

Loop

TextBox1.Text = builder.ToString()

--
Milosz Skalecki
MCAD

"rodchar" wrote:

Quote:

Originally Posted by

hey all,
i'm trying to read a text document line by line into a stringbuilder and an
issue i'm running into is this:
do while streamReader.ReadLine
stringBuilder.Append("my string" & string.ReadLine)
is showing up like this:
"my string"
value
>
instead of
"my string" value
>
how do i keep the value on the same line as my string?
>
thanks,
rodchar

string.split and Environment.NewLine question.

greetings...

i want to split a new line from an input text area and here's what i did

string.Split("\n \r ", ",");
the result, nothing happen...

then i tried this

string.Split(Environment.NewLine, ",");
and got the result what i wanted..
the question here is, why cant the 1st method work? whats wrong with it?The Environment.NewLine does not equal "\n \r "

The new line and carriage return characters are the wrong way round, and
cannot have any spaces between them.
Try this: "\r\n" (which is equal to Environment.NewLine)

"Asha" <Asha@.discussions.microsoft.com> wrote in message
news:984D487F-F0B9-462E-AFEA-BF1BE6BF4A3F@.microsoft.com...
> greetings...
> i want to split a new line from an input text area and here's what i did
> string.Split("\n \r ", ",");
> the result, nothing happen...
> then i tried this
> string.Split(Environment.NewLine, ",");
> and got the result what i wanted..
> the question here is, why cant the 1st method work? whats wrong with it?

string.split and Environment.NewLine question.

greetings...
i want to split a new line from an input text area and here's what i did
string.Split("\n \r ", ",");
the result, nothing happen...
then i tried this
string.Split(Environment.NewLine, ",");
and got the result what i wanted..
the question here is, why cant the 1st method work? whats wrong with it?The Environment.NewLine does not equal "\n \r "
The new line and carriage return characters are the wrong way round, and
cannot have any spaces between them.
Try this: "\r\n" (which is equal to Environment.NewLine)
"Asha" <Asha@.discussions.microsoft.com> wrote in message
news:984D487F-F0B9-462E-AFEA-BF1BE6BF4A3F@.microsoft.com...
> greetings...
> i want to split a new line from an input text area and here's what i did
> string.Split("\n \r ", ",");
> the result, nothing happen...
> then i tried this
> string.Split(Environment.NewLine, ",");
> and got the result what i wanted..
> the question here is, why cant the 1st method work? whats wrong with it?

Monday, March 26, 2012

String/Number manip.

In the following line:
txtWage.Text = "$" & Trim(dataReader.GetValue(9).ToString)

It returns $20.0000 I only want it to return back $20.00 -- every search I've done in string manip. has shown me zilch.

Any suggestions?

txtWage.Text = Format(CDbl(Trim(dataReader.GetValue(9).ToString)), "currency")
I think you can use String.Format also to do the same thing, with the format of {0:c}

StringBuilder and objMail

I am new to ASP.NET so please be gentle :-)
I am trying to build an text (not HTML) email. I am putting together the
string that will be the body of the email but the formatting keeps getting
messed up. See code below.

Thanks in advance for any help you can give!

I want it to look like this...

Thank you for ordering from mycompany.com!

Your order is being billed to:
John Smith

******** But it keeps coming out like **************

Thank you for ordering from mycompany.com!Your order is being billed to: "
John Smith

******* Here is my code ********
Dim sEmail As New System.Text.StringBuilder

sEmail.Append("Thank you for ordering from mycompany.com!" & Chr(13))
sEmail.Append("Your order is being billed to: " & Chr(34))
sEmail.Append(Chr(32) & rdrMbrs.Item("fullname"))

objMail.Body = sEmail.toString()

Quote:

Originally Posted by

******** But it keeps coming out like **************
>
Thank you for ordering from mycompany.com!Your order is being billed to: "
John Smith
>
>
******* Here is my code ********
sEmail.Append("Thank you for ordering from mycompany.com!" & Chr(13))
sEmail.Append("Your order is being billed to: " & Chr(34))
sEmail.Append(Chr(32) & rdrMbrs.Item("fullname"))


The newline in the internet world is not Chr(13) which is only
carriage-return.

The newline if CRLF:
Chr(13) & Chr(10)

I'm not sure but I think vbCrlf - constant - should be automatically
available to VB.Net programmers. It used to be there in VB6 and I think
should exist even now.

See this page for a good discussion:
http://en.wikipedia.org/wiki/Newline
HTH

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-------------
I agree with Gaurav. However, a better approach is to use
System.Environment.NewLine.

Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
>I agree with Gaurav. However, a better approach is to use

Quote:

Originally Posted by

System.Environment.NewLine.


Not sure if System.Environment.NewLine is a good approach since again, we
are going to OS specific newline which is CRLF on Windows, CR on Mac and LF
on Unix/Linux etc.

Ok... if we are working with Microsoft .Net Framework, we know that we are
on Windows and it will translate to CRLF.

But I would like to play safe. Although an impossible probability today, but
what if Microsoft plans to release it on other OS as well ;)

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-------------
Hi Gaurav,

Using System.Environment.NewLine is the preferred way to represent a
"NewLine"; although you're right that the internal implementation of this
read-only property currently is implemented as:

public static string NewLine
{
get
{
return "\r\n";
}
}

However, consider someday your code is going to run on other platform, your
code doesn't have to be modified since you're calling into the BCL (Base
Class Library). I believe the BCL on different platform should return the
new line constant accordingly.

#Brad Abrams : Pet Peeve #493: Console.WriteLine ("\n")
http://blogs.msdn.com/brada/archive.../08/211053.aspx
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Quote:

Originally Posted by

However, consider someday your code is going to run on other platform,
your
code doesn't have to be modified since you're calling into the BCL (Base
Class Library). I believe the BCL on different platform should return the
new line constant accordingly.


I agree. I use it as the way to write a new-line (mainly since I also work
with Mono at times).

But hey! Hold on... the original problem was in the mail-message being sent.
In the mail-message composed, Environment.NewLine is definitely a very bad
choice.
There cannot be any choice other than CRLF (="\r\n" or "Chr(13) & Chr(10)").

I still hold on to my point that Environment.NewLine should not be used to
indicate a new-line while composing a mail.

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-------------
This worked great!!! Chr(13) & Chr(10) Thanks everyone for all you help.
One more thing why does the tab also not work? Chr(32)

Thanks Again!

"Gaurav Vaish (MasterGaurav)" <gaurav.vaish.nospam@.nospam.gmail.comwrote
in message news:%2374qm4VQHHA.3444@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>

Quote:

Originally Posted by

>However, consider someday your code is going to run on other platform,
>your
>code doesn't have to be modified since you're calling into the BCL (Base
>Class Library). I believe the BCL on different platform should return the
>new line constant accordingly.


>
I agree. I use it as the way to write a new-line (mainly since I also work
with Mono at times).
>
But hey! Hold on... the original problem was in the mail-message being
sent.
In the mail-message composed, Environment.NewLine is definitely a very bad
choice.
There cannot be any choice other than CRLF (="\r\n" or "Chr(13) &
Chr(10)").
>
I still hold on to my point that Environment.NewLine should not be used to
indicate a new-line while composing a mail.
>
>
>
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-------------
>
>


"Rick" <rick@.di-wave.comwrote in message
news:OuKqUIWQHHA.496@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

This worked great!!! Chr(13) & Chr(10) Thanks everyone for all you help.
One more thing why does the tab also not work? Chr(32)


Chr(32) is a <space>
Chr(9) is a <tab>
Thanks very much!!

"Mark Rae" <mark@.markNOSPAMrae.comwrote in message
news:e%23E1InWQHHA.5032@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

"Rick" <rick@.di-wave.comwrote in message
news:OuKqUIWQHHA.496@.TK2MSFTNGP06.phx.gbl...
>

Quote:

Originally Posted by

>This worked great!!! Chr(13) & Chr(10) Thanks everyone for all you help.
>One more thing why does the tab also not work? Chr(32)


>
Chr(32) is a <space>
Chr(9) is a <tab>
>


My apology for ignoring the requirement is to use the line breaks in email
message. According to RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt), the
Line Break in a text body must use a CRLF sequence.

I hope I didn't cause too much confusion.

Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
My apology for ignoring the requirement is to use the line breaks in email

Quote:

Originally Posted by

message. According to RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt), the
Line Break in a text body must use a CRLF sequence.


That's ok.
btw, that's not just an RFC-2045 requirement but also elsewhere like in HTTP
etc.
CRLF is the "NewLine" of the "Internet" and specifically, "the Web".

Quote:

Originally Posted by

I hope I didn't cause too much confusion.


I hope not. :)

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-------------

StringBuilder AppendLine dont print Line breaks in my emails!

Hello... I'm working with StringBuilder to create a message to send via text email.

My methos is:

StringBuilder retorno = new StringBuilder();

retorno.AppendLine ( "A lot of text 1" );
retorno.AppendLine ( "A lot of text 2" );

return retorno.ToString() ;

Well.. I this last line I return the text to the message, but the email arrives without line breaks.

What can i do? thanks!

if you email format is in HTML, then you can use tag "<BR>" to create a line break

StringBuilder sb = new StringBuilder();
sb.Append("A lot of text 1");
sb.Append("<br>");
sb.Append("A lot of text 2);
return retorno.ToString() ;

else

you may try using \r\n, sb.Append("XXX\\r\\nXXXX");


have you tried for this one ?? it shoud work as it worked for me..

 StringBuilder retorno =new StringBuilder(); retorno.AppendLine("A lot of text 1"); retorno.AppendLine("<br />"); //....append a <br /> Tag... retorno.AppendLine("A lot of text 2"); Response.Write(retorno.ToString());

hope it helps./.

stringbuilder help

Dim sbRegX As New StringBuilder(HttpUtility.HtmlEncode(txtComments.Text))
sbRegX.Replace("<a>", "<a>")
sbRegX.Replace("</a>", "")
How do I get the attributes of href and target to be encoded?"Aaron" <fromtheweb@.aaronminoo.com> schrieb:
>Dim sbRegX As New StringBuilder(HttpUtility.HtmlEncode(txtComments.Text))
>sbRegX.Replace("<a>", "<a>")
>sbRegX.Replace("</a>", "")
>How do I get the attributes of href and target to be encoded?
Encoded as what?
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried,
I have a text box that could have <a href="http://links.10026.com/?link=yahoo.com"
target="_new">yahoo</a>
With just
sbRegX.Replace("<a>", "<a>")
sbRegX.Replace("</a>", ""</a> )
The output is
<a href="http://links.10026.com/?link=yahoo.com" target="_blank">Yahoo
and the data looks like this
<a href="yahoo.com"
target="_blank">Yahoo</a>,
I need it to look like http://www.yahoo.com with it in a new window.
TIA
Aaron
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@.gmx.at> wrote in message
news:uEsaI%23CIGHA.3944@.tk2msftngp13.phx.gbl...
> "Aaron" <fromtheweb@.aaronminoo.com> schrieb:
> Encoded as what?
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>
Aaron,
You'll be looking for Server.HtmlEncode and Server.HtmlDecode. You may also
want to experiment (depending on all the uses of the input text) with
Sever.UrlEncode and Server.UrlDecode.
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Aaron" <fromtheweb@.aaronminoo.com> wrote in message
news:eGhc$WDIGHA.3728@.tk2msftngp13.phx.gbl...
> Herfried,
> I have a text box that could have <a href="http://links.10026.com/?link=yahoo.com"
> target="_new">yahoo</a>
> With just
> sbRegX.Replace("<a>", "<a>")
> sbRegX.Replace("</a>", ""</a> )
> The output is
> <a href="http://links.10026.com/?link=yahoo.com" target="_blank">Yahoo
> and the data looks like this
> <a href="yahoo.com"
> target="_blank">Yahoo</a>,
>
> I need it to look like http://www.yahoo.com with it in a new window.
> TIA
> Aaron
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@.gmx.at> wrote in message
> news:uEsaI%23CIGHA.3944@.tk2msftngp13.phx.gbl...
>

Stringbuilder Parsing Text: Need to remove square character

Hi everyone,

I am attempting to parse data from a webpage and want to remove any unneccesary junk from the string. I start by removing any Tags from the text I have retrieved from the web page. Next, I split the text into an array. However, I end up with a string that contains a bunch of characters that look like ?, sometimes there are many in a row: ???? in each string. I would like to remove these characters.

These characters are the only things left separating me from the data I want, but I am not sure how to remove them... Does anyone have an idea? It is interesting that when I display my string in a textbox, or using a label, the squares are not visible (I think they display as spaces) but when I debug I see them.

Thanks,

zoop

Those chars probably are line feeds, tabs or some other control chars.

Try:

Dim junk asString ="bla bla bla....."

junk=junk.replace(ControlChars.Lf,"")

junk=junk.replace(ControlChars.NewLine,"")

junk=junk.replace(ControlChars.Tab,"")


etc, etc...


If I'm not mistaken you are seeing the hidden space place holder. You can use regular expressions to remove them. Try something like below to remove them.

using System.Text.RegularExpressions;

private string StripSpaces(string inputString)
{
return Regex.Replace(inputString, @."[^\s$]","");
}


Thanks for the input fellas. I have tried the suggestions above along with some variations and came up short. Replacing the ControlChars does not seem to make a difference on the format of the string. Running the stripSpaces function removes all of the data I am interested in and returns only the chars I am attempting to remove (blanks, or squares). Perhaps I lost something when I translated it into VB...

Anyway, since there is not much code to go over I thought perhaps it would help if I posted what I have here. I am going to omit the section where I replace any ControlChars for brevity, as it does not seem to make a difference.

1Private Sub btnSubmit_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnSubmit.Click2'// Store Page Source in DOC3Dim reqAs WebRequest = WebRequest.Create("http://world5.knightfight.co.uk/index.php?ac=highscore&vid=0")4Dim respAs WebResponse = req.GetResponse56Dim sAs Stream = resp.GetResponseStream7Dim srAs StreamReader =New StreamReader(s, Encoding.ASCII)8Dim docAs String = sr.ReadToEnd910'// Format text in DOC using StringBuilder Class11Dim sbAs StringBuilder =New StringBuilder(doc)12Dim endIndexAs Integer = sb.ToString.IndexOf("showuserid=")13Dim newString()As String14Dim strTestAs String1516'// Remove Unwanted Text17strTest = sb.Remove(0, endIndex).ToString1819'// Remove HTML Tags and Spaces20strTest = StripTags(strTest)21strTest = stripSpaces(strTest)2223'// TEMP - Display Preview in Multiline Textbox24txtbWebData.Text = strTest2526'// Split String into Array27newString = Split(strTest," ")28End Sub2930Public Function StripTags(ByVal HTMLAs String)As String31' Removes tags from passed HTML32Dim objRegExAs _33System.Text.RegularExpressions.Regex34Return objRegEx.Replace(HTML,"<[^>]*>","*")35End Function3637Public Function stripSpaces(ByVal inputStringAs String)As String38Dim objRegExAs _39System.Text.RegularExpressions.Regex40Return objRegEx.Replace(inputString,"[^\s$]","")41End Function42

I thought it would be an interesting exercise to try and capture some data from a highscores list on a website. The URL is in the code above, http://world5.knightfight.co.uk/index.php?ac=highscore&vid=0,so you could reproduce my results if you like. The end goal is to capture the data in the highscores list and format it in a way that makes sense. If you think there is a better approach please let me know :).

Thanks,

zoop


Sorry about that. Replace Return objRegEx.Replace(inputString, "[^\s$]", "") with Return objRegEx.Replace(inputString, "[^\S$]", ""). The \s matches any white space character and the \S matches any non-white space character.

StringBuilder to Text

Hello, I a m building an email message in a StringBuilder Object and then
using the StringBuilder ToString() method to get it to regular text. It
appears to me that when I place a "\n" into the Stringbuilder object that
when this is translated into text, I loose the page break. Is this true and
I doing something wrong?
I'm guessing that I could insert a special character into the StringBuilder
object and then use the string Replace() method to translate that special
character into a "\n" and perhaps this would work.
Just wondering why it does not work when I place that value into the
StringBuilder Object.
ThanksHow are you noticing that you loose the break? In what context is this
happening?
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks
Have you considered using Environment.Newline instead of "\n"?
Example:
StringBuilder textBuilder = new StringBuilder(512);
textBuilder.Append("Dear John,");
textBuilder.Append(Environment.Newline)
Perhaps that will help.
carl
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks
Try Environment.NewLine
Remy
I am loosing the page break when I use the StringBuilder ToString() method
when I am formatting an email message. I will try the Environment.NewLine()
method and see if that retains the line break.
Does the StringBuilder cause the newline disappear, or is it something with
the mail component. What happens if you just set the
StringBuilder.ToString() to a variable and looked at it, is the newline
gone?
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:9876DF24-F310-4FDC-826D-D7872576655C@.microsoft.com...
>I am loosing the page break when I use the StringBuilder ToString() method
> when I am formatting an email message. I will try the
> Environment.NewLine()
> method and see if that retains the line break.
>
I assume you are using c?
If you pass "\n" you'll get newline > chr(10)
If you want "\n" you might consider to use "\\n"
(Outlook express mangels this for me, use slash twice)
"Jim Heavey" <JimHeavey@.discussions.microsoft.com> schreef in bericht
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks

StringBuilder to Text

Hello, I a m building an email message in a StringBuilder Object and then
using the StringBuilder ToString() method to get it to regular text. It
appears to me that when I place a "\n" into the Stringbuilder object that
when this is translated into text, I loose the page break. Is this true and
I doing something wrong?

I'm guessing that I could insert a special character into the StringBuilder
object and then use the string Replace() method to translate that special
character into a "\n" and perhaps this would work.

Just wondering why it does not work when I place that value into the
StringBuilder Object.

ThanksHow are you noticing that you loose the break? In what context is this
happening?

"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks
Have you considered using Environment.Newline instead of "\n"?

Example:

StringBuilder textBuilder = new StringBuilder(512);
textBuilder.Append("Dear John,");
textBuilder.Append(Environment.Newline)

Perhaps that will help.

carl

"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks
Try Environment.NewLine

Remy
I am loosing the page break when I use the StringBuilder ToString() method
when I am formatting an email message. I will try the Environment.NewLine()
method and see if that retains the line break.
Does the StringBuilder cause the newline disappear, or is it something with
the mail component. What happens if you just set the
StringBuilder.ToString() to a variable and looked at it, is the newline
gone?

"Jim Heavey" <JimHeavey@.discussions.microsoft.com> wrote in message
news:9876DF24-F310-4FDC-826D-D7872576655C@.microsoft.com...
>I am loosing the page break when I use the StringBuilder ToString() method
> when I am formatting an email message. I will try the
> Environment.NewLine()
> method and see if that retains the line break.
I assume you are using c?

If you pass "\n" you'll get newline > chr(10)
If you want "\n" you might consider to use "\\n"
(Outlook express mangels this for me, use slash twice)

"Jim Heavey" <JimHeavey@.discussions.microsoft.com> schreef in bericht
news:1BC14F11-5DBA-4865-9CFB-2881598EB955@.microsoft.com...
> Hello, I a m building an email message in a StringBuilder Object and then
> using the StringBuilder ToString() method to get it to regular text. It
> appears to me that when I place a "\n" into the Stringbuilder object that
> when this is translated into text, I loose the page break. Is this true
> and
> I doing something wrong?
> I'm guessing that I could insert a special character into the
> StringBuilder
> object and then use the string Replace() method to translate that special
> character into a "\n" and perhaps this would work.
> Just wondering why it does not work when I place that value into the
> StringBuilder Object.
> Thanks

Saturday, March 24, 2012

Strip HTML from Text

Is there an easy way to strip HTML tags from Text to get just the plain
text?
I am using a program called FreeTextBox that lets you format Text in a
TextBox. It does this by adding HTML tags (<b>, <u>,<span> etc) to the
code.
The problem is that it is a problem since I am putting the text in a
varChar(8000). The HTML adds a lot characters to the text. I can change
this to a Text field in Sql, but you can do a FullText search on a Text
field (plus I don't really want the tags in a Text Search).
Is there some filtering mechanism that would strip the HTML from a text
field?
Thanks,
TomHere's a complete sample :
http://www.experience247.com/srcvie...tmlIn.cs&font=3
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
> Is there an easy way to strip HTML tags from Text to get just the plain te
xt?
> I am using a program called FreeTextBox that lets you format Text in a Tex
tBox. It does this by
> adding HTML tags (<b>, <u>,<span> etc) to the code.
> The problem is that it is a problem since I am putting the text in a varCh
ar(8000). The HTML adds
> a lot characters to the text. I can change this to a Text field in Sql, b
ut you can do a FullText
> search on a Text field (plus I don't really want the tags in a Text Search
).
> Is there some filtering mechanism that would strip the HTML from a text fi
eld?
> Thanks,
> Tom
>
That does what I was looking for.
Thanks,
Tom
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:OMXrAJlPGHA.4952@.TK2MSFTNGP09.phx.gbl...
> Here's a complete sample :
> http://www.experience247.com/srcvie...tmlIn.cs&font=3
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en espaol : http://asp.net.do/foros/
> ===================================
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
>