Wednesday, March 28, 2012

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
>.

0 comments:

Post a Comment