Solved

Converting a String Variable

Posted on 1997-11-18
5
210 Views
Last Modified: 2010-04-16
How can I convert a String variable that holds a value of NA to a space.  I call a stored procedure and fill the values of a Developer object called Dev as you see below.  If fields in the developer table are empty, I pass back NA for Not Available.  The problem is that, I do not want to display NA in a textfield, if say for example, a developer does not have an email address.

txtEmail.setText((Dev.getemail()).toUpperCase());
txtAddress1.setText((Dev.getaddress1()).toUpperCase());


Instead of setting the text of the textField immediately, I can put them in local String variables such as l_email, l_address1.  If the value of one of these variables is NA, how can I dynamically check this and assign a space so that l_email = " ";

Then I can do txtEmail.setText(l_email);, so that the user does not see this NA.

Any ideas???

Thanks
0
Comment
Question by:kpetti
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
maha earned 50 total points
ID: 1230899
I am not pretty sure whether I got Ur question correctly.
There are 2 ways to do it,
One way is ,
  String sTmp = Dev.getemail().toUpperCase();
  if((sTmp.equals("NA")) == true)
      txtEmail.setText("");
  else
      txtEmail.setText(sTmp);

   If U donot want to do it eveytime for all the fields, U extend the String class and override getText function in derived class say MyString and return space if the data is "NA"

 Hope it helps,
Maha


0
 

Author Comment

by:kpetti
ID: 1230900
Maha,

That helps very much.  Thank you.  Would you be able to place give a code snippet for you second suggestion:

If U donot want to do it eveytime for all the fields, U extend the String class and override getText function in derived class
say MyString and return space if the data is "NA"

Thanks again
0
 

Expert Comment

by:maha
ID: 1230901
Hi there,

  sorry for wrong answer( part of it). Actually second option is not feasible. I confused String class with Label or TextField. But first soln will work fine.

Maha

0
 

Author Comment

by:kpetti
ID: 1230902
Maha,

Is there a more efficient way to do this?  I have about 15 textFields and the code is a little sloppy with all of the if...else statements.  The suggestion you made works well and I appreciate the help.  If you can think of a method that can be written please let me know.  I was thinking something like:

public String convertNA(String s)
{  
   StringBuffer stringBuff = new StringBuffer;

Is there a way to call a convertNA(l_address1) method?  I am not sure how to do this.  Any ideas?

Thanks,

kpetti

0
 

Expert Comment

by:maha
ID: 1230903
Hi kpetti,

Well, if U r planning to do it for TextFields only, there is a way to do it. U need to extend TextField class and override setText. Here is sample code

class MyTextField extends TextField
{

     public void setText (String text)
     {
         if((text.equals("NA")) == true)
             super.setText("");
         else
             super.setText(text);
     }
}
and change all Ur text fields to MyTextField type. In this case, U donot have to code all if--elses. Try it out and let me know.

Maha

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

758 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

19 Experts available now in Live!

Get 1:1 Help Now