Solved

Converting a String Variable

Posted on 1997-11-18
5
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
hibernate example using maven 12 108
Java class and jar 3 60
Delete .class files at every compile 4 57
Eclipse neon2 "Java build path" correctness 7 43
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
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 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:
Suggested Courses

734 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