Solved

String format

Posted on 2004-10-19
2
202 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
Comment Utility
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
Comment Utility
Did this address your need? There is no other way of doing what you are thinking of
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now