Solved

String format

Posted on 2004-10-19
2
222 Views
Last Modified: 2010-04-15
Hey,

In my aspx-app I do the following

this.TextBox1.text = object.property.tostring("N")

How can I force that when the value of the property (= Int32) = 0 that it is a space and not 0 in my textbox. I will have an empty textbox.:

Now I do (and I think there is something shorter)

if (object.property == 0)
   this.TextBox1.text = "";
else
   this.TextBox1.text = object.property.tostring();







Thanks
nic
0
Comment
Question by:haezeban
  • 2
2 Comments
 
LVL 3

Expert Comment

by:aacool
ID: 12347216
Well, you can use the ternary operator - this is one-line. It does not save much in the current case.

(object.property == 0) ? TextBox1.Text="" : TextBox1.Text = object.property.ToString();

If you have this kind of check in many places, perhaps you can put in a function with the code above and call it wherever needed.

e.g
Use
SetTxt(TextBox1,object.property);

Calls this function
private void SetTxt(System.Windows.Forms.TextBox TextBox1,object prop)
{
   (prop == 0) ? TextBox1.Text="" : TextBox1.Text = prop.ToString();
}
0
 
LVL 3

Accepted Solution

by:
aacool earned 50 total points
ID: 12377104
Did this address your need? There is no other way of doing what you are thinking of
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question