Solved

Converting a String Variable

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 45
map related example 6 55
spring jars download 1 35
by zero exception 10 51
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

765 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