PC Review


Reply
Thread Tools Rate Thread

How can I do to remove the string s

 
 
Tony Johansson
Guest
Posts: n/a
 
      10th May 2011
Hello!

If I do the following I get compile error says It's not possible to implicit
convert the type string to bool
Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
"true" : "false";

Can I write in another way so I can remove the s string in this code.


protected void Page_Load(object sender, EventArgs e)
{
string s;
Label1.Text = "Application path is : " + Request.Path;
Label2.Text = "OS platform is : " + Request.Browser.Platform;
Label3.Text = "Browser type is : " + Request.Browser.Type;
s = Request.Browser.Cookies ? "true" : "false";
Label4.Text = "Browser support cookies : " + s;
s = Request.Browser.VBScript ? "true" : "false";
Label5.Text = "Browser support VBScript : " + s;
s = Request.Browser.JavaScript ? "true" : "false";
Label6.Text = "Browser support JavaScript : " + s;
Label7.Text = "Browser is using :" + Request.HttpMethod + " data
transfer method";
}

//Tony



 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      10th May 2011
On 10-05-2011 16:20, Tony Johansson wrote:
> Hello!
>
> If I do the following I get compile error says It's not possible to implicit
> convert the type string to bool
> Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
> "true" : "false";
>
> Can I write in another way so I can remove the s string in this code.


Try:

Label4.Text = "Browser support cookies : " + (Request.Browser.Cookies ?
"true" : "false");

or maybe:

Label4.Text = "Browser support cookies : " + Request.Browser.Cookies;

Arne
 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      10th May 2011
I found it myself I just used Convert.ToString in this way.
Label4.Text = "Browser support cookies :" +
Convert.ToString(Request.Browser.Cookies ? true : false);

//Tony


"Tony Johansson" <(E-Mail Removed)> skrev i meddelandet
news:iqc9cd$ruk$(E-Mail Removed)...
> Hello!
>
> If I do the following I get compile error says It's not possible to
> implicit
> convert the type string to bool
> Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
> "true" : "false";
>
> Can I write in another way so I can remove the s string in this code.
>
>
> protected void Page_Load(object sender, EventArgs e)
> {
> string s;
> Label1.Text = "Application path is : " + Request.Path;
> Label2.Text = "OS platform is : " + Request.Browser.Platform;
> Label3.Text = "Browser type is : " + Request.Browser.Type;
> s = Request.Browser.Cookies ? "true" : "false";
> Label4.Text = "Browser support cookies : " + s;
> s = Request.Browser.VBScript ? "true" : "false";
> Label5.Text = "Browser support VBScript : " + s;
> s = Request.Browser.JavaScript ? "true" : "false";
> Label6.Text = "Browser support JavaScript : " + s;
> Label7.Text = "Browser is using :" + Request.HttpMethod + " data
> transfer method";
> }
>
> //Tony
>
>
>



 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      10th May 2011
On 10-05-2011 17:37, Tony Johansson wrote:
> "Tony Johansson"<(E-Mail Removed)> skrev i meddelandet
> news:iqc9cd$ruk$(E-Mail Removed)...
>> Hello!
>>
>> If I do the following I get compile error says It's not possible to
>> implicit
>> convert the type string to bool
>> Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
>> "true" : "false";
>>
>> Can I write in another way so I can remove the s string in this code.
>>
>>
>> protected void Page_Load(object sender, EventArgs e)
>> {
>> string s;
>> Label1.Text = "Application path is : " + Request.Path;
>> Label2.Text = "OS platform is : " + Request.Browser.Platform;
>> Label3.Text = "Browser type is : " + Request.Browser.Type;
>> s = Request.Browser.Cookies ? "true" : "false";
>> Label4.Text = "Browser support cookies : " + s;
>> s = Request.Browser.VBScript ? "true" : "false";
>> Label5.Text = "Browser support VBScript : " + s;
>> s = Request.Browser.JavaScript ? "true" : "false";
>> Label6.Text = "Browser support JavaScript : " + s;
>> Label7.Text = "Browser is using :" + Request.HttpMethod + " data
>> transfer method";
>> }


> I found it myself I just used Convert.ToString in this way.
> Label4.Text = "Browser support cookies :" +
> Convert.ToString(Request.Browser.Cookies ? true : false);


That code can be shortened!

Label4.Text = "Browser support cookies :" + Request.Browser.Cookies;

works the same way.

Arne
 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      10th May 2011
"Tony Johansson" <(E-Mail Removed)> wrote in message
news:iqcb5t$20r$(E-Mail Removed)...

> Convert.ToString(Request.Browser.Cookies ? true : false);


Stop and think about this code:

Request.Browser.Cookies ? true : false

The Cookies property is a Boolean. You're testing it (for "trueness") and
returning...a Boolean! Just use the value itself instead of translating it
into...itself!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove string from string Brian Microsoft Access Forms 1 12th Jun 2008 10:13 PM
Remove specified string from value Todd Huttenstine Microsoft Excel Programming 1 31st Jan 2006 05:13 PM
Remove specified value from string Todd Huttenstine Microsoft Excel Programming 2 31st Jan 2006 04:48 PM
Q: remove a certain string in string =?Utf-8?B?SklNLkgu?= Microsoft ASP .NET 2 28th Feb 2005 02:02 AM
String.Remove vs String.Substring Janaka Microsoft Dot NET Framework 2 5th Nov 2003 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:03 PM.