Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have problem in printing & in string

Eg :

string Test="This is the example & excercise "

but while print that string in lable it shows as

This is the example

& is not printed in label

Any one help pls.
Posted
Comments
AmitGajjar 22-Aug-12 0:22am    
use & emp; instead of &
ridoy 22-Aug-12 2:44am    
strange problem,i test your code,but it works fine for me.The label prints it as like in string Test!

here are two solutions,
both will work in window application but for web application use second solution.

1. set labels property 'UseMnemonic'='False'
C#
label1.UseMnemonic=false;
label1.Text="This is the example & excercise";
//will show you same string as you assign in text property.


2. Replace with '&' with '&&'.
C#
label1.Text="This is the example & excercise".Replace("&","&&");

Happy Coding!
:)
 
Share this answer
 
Try this

C#
string Test = "This is the example && excercise ";
label1.Text = Test;
 
Share this answer
 
C#
string Test="This is the example && excercise " 

or if it is kind of input string , then use replace

C#
string Test="This is the example & excercise "
Test.Replace("&","&&") 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900