Solved

Converting a String Variable

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

679 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