Single Quote

I am writing the code to convert single quote to double quote while inserting into record and double quote to single quote while getting back from records. But I doubt the code I have written could you check up for me.

public void setFirstName(){

 if( (int=firstName.indexOf(' ' ')!= -1){
  firstName=firstName.replace(  ' ' ', ' '' ' );
  }
  this.firstName=firstName;
 }
 
 


public String getFirstName(){
 
  if( (int i=firstName.indexOf(' '' '))!= -1){
     firstName=firstName.replace( ' '' ',' ' ' );
   }
   return firstName;
 
  }

rmvprasadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
firstName=firstName.replace(  ' \' ', ' \'' ' );

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimYatesCommented:
errr...

why?

Is this for writing to a database?

Use PreparedStatement

    PreparedStatement stmt = conn.prepareStatement( "INSERT INTO users VALUES ( ?, ? )" ) ;
    stmt.setString( 1, firstName ) ;
    stmt.setString( 2, surname ) ;

Tim
Tommy BraasCommented:
Another question; why do you have the single quotes in the string to begin with?
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

TimYatesCommented:
I guess for names like:

    Louis O'Dwyer
    Barry 'The Fish' Crossman

etc... :-/

Not sure though...I can't think of any "firstNames" which have quotes...
therichytCommented:
public void setFirstName() {
 if( (int=firstName.indexOf(' ' ')!= -1){
     firstName=firstName.replace("\'","\"");
  }
  this.firstName=firstName;
 }
 
 


public String getFirstName() {
  if( (int i=firstName.indexOf(' '' '))!= -1){
     firstName=firstName.replace("\"","\'");
   }
   return firstName;
}
therichytCommented:
Sorry,

public void setFirstName() {
 if( (int=firstName.indexOf("\")!= -1){
     firstName=firstName.replace("\'","\"");
  }
  this.firstName=firstName;
 }
 
public String getFirstName() {
  if( (int i=firstName.indexOf("\""))!= -1){
     firstName=firstName.replace("\"","\'");
   }
   return firstName;
}

I believe that will work.
CEHJCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.