Solved

Converting a String Variable

Posted on 1997-11-18
5
211 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split string containing \r\n in Java 46 38
windows explorer path to command prompt 5 33
Oracle SQL syntax check  without executing 6 38
even odd program using while loop 3 31
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

864 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

22 Experts available now in Live!

Get 1:1 Help Now