converting a string to an expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kusuma chalasani
    New Member
    • Jan 2007
    • 19

    converting a string to an expression

    hii..
    i want to convert a string into an expression.for example,
    if "j=1" is a string then i want to change it into an expression j=1 and i want to use that in running my program in java..
    please give me the solution for this..
    thank u..
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kusuma chalasani
    hii..
    i want to convert a string into an expression.for example,
    if "j=1" is a string then i want to change it into an expression j=1 and i want to use that in running my program in java..
    please give me the solution for this..
    thank u..
    I doubt if this is what you really want to do. Revise your design. Tell us what you want your program to achieve and there should be a better way of acieving your required functionality.

    Comment

    • kusuma chalasani
      New Member
      • Jan 2007
      • 19

      #3
      i want my applet to change dynamically according to the change in variable.
      in my program, i want to retrieve a string ( "redfail=tr ue") from the database and i want that redfail=true which should act as a boolean in the run method and according to this redfail value, some changes wil occur in the applet.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kusuma chalasani
        i want my applet to change dynamically according to the change in variable.
        in my program, i want to retrieve a string ( "redfail=tr ue") from the database and i want that redfail=true which should act as a boolean in the run method and according to this redfail value, some changes wil occur in the applet.
        That's better.

        Now you just get the value from the db into a boolean variable and compare with
        Code:
         if(value) { 
        //make changes
        }
        else {
        //make different changes
        }
        Now are you having a problem with any of this?

        Comment

        • kusuma chalasani
          New Member
          • Jan 2007
          • 19

          #5
          Originally posted by r035198x
          That's better.

          Now you just get the value from the db into a boolean variable and compare with
          Code:
           if(value) { 
          //make changes
          }
          else {
          //make different changes
          }
          Now are you having a problem with any of this?

          I didnt get what the value mean???

          In my program i'm retrieving a string as "redfail=tr ue" from db. and i'm going to use the value of the boolean variable 'redfail'.
          ie
          boolean redfail=false;

          .
          .
          String s="redfail=true "; // s is retrieving from database
          .
          .
          if(redfail==tru e) //how can i change the value of redfail as true according to the
          // result from the database?
          {
          .
          .
          }
          i think my doubt is clear now..
          Thank u..

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Code:
             String s="redfail=true"; 
            String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
            boolean value = strings[1].equalsIgnoreCase("true") ? true:false;
            if(value) {
             
            ///
            }
            else {
            //
            }

            Comment

            • kusuma chalasani
              New Member
              • Jan 2007
              • 19

              #7
              thank u very much..

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by kusuma chalasani
                thank u very much..
                I take it you managed to get it work properly?

                Comment

                • kusuma chalasani
                  New Member
                  • Jan 2007
                  • 19

                  #9
                  Thank u..
                  i have one doubt..
                  cant we change the string " redfail=true" to a
                  statement like redfail=true; ?

                  Originally posted by kusuma
                  Code:
                   boolean redfail=false;
                  .
                  .
                  String s="redfail=true"; // s is retrieving from database
                  .
                  .
                  
                  redfail==true ;//how can i change the value of redfail as true according to the 
                                     // result from the database?

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by kusuma chalasani
                    Thank u..
                    i have one doubt..
                    cant we change the string " redfail=true" to a
                    statement like redfail=true; ?
                    Just give it the value of the variable value from the previous code I posted


                    Code:
                     
                    String s="redfail=true"; 
                    String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
                    redfail = strings[1].equalsIgnoreCase("true") ? true:false;
                    In this case if the string is "redfail=tr ue", then the variable redfail is assigned true otherwise it is assigned false.

                    Comment

                    • jipsonpj
                      New Member
                      • Mar 2007
                      • 2

                      #11
                      hai ..........
                      i am jipson
                      i have one doute in c++
                      can you help me

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by jipsonpj
                        hai ..........
                        i am jipson
                        i have one doute in c++
                        can you help me
                        The c++ forum is here. Post a new thread thread there for your problem. Remember to give a title that best explains your problem.

                        Comment

                        • kusuma chalasani
                          New Member
                          • Jan 2007
                          • 19

                          #13
                          Originally posted by r035198x
                          Just give it the value of the variable value from the previous code I posted


                          Code:
                           
                          String s="redfail=true"; 
                          String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
                          redfail = strings[1].equalsIgnoreCase("true") ? true:false;
                          In this case if the string is "redfail=tr ue", then the variable redfail is assigned true otherwise it is assigned false.
                          thank u..
                          in my program i have to retrieve so many strings at a time. i.e., there are so many variables like redfail,redsefa il,greenfail,gr eenfail and many more...
                          instead of writing code for every variable, is there any other option to make strings[0] in the above code can be used directly as a variable????

                          Comment

                          • kusuma chalasani
                            New Member
                            • Jan 2007
                            • 19

                            #14
                            Originally posted by kusuma chalasani
                            thank u..
                            in my program i have to retrieve so many strings at a time. i.e., there are so many variables like redfail,redsefa il,greenfail,gr eenfail and many more...
                            instead of writing code for every variable, is there any other option to make strings[0] in the above code can be used directly as a variable????

                            to be clear..
                            as ther were so many variables in the program..
                            instead of writing code for every variable like

                            if(strings[0].equals("redfai l"))
                            redfail = strings[1].equalsIgnoreCa se("true") ? true:false;
                            if(strings[0].equals("redsef ail"))
                            redsefail=strin gs[1].equalsIgnoreCa se("true") ? true:false;
                            .
                            .
                            is there any other option to make strings[0] in the above code can be used directly as a variable.

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by kusuma chalasani
                              to be clear..
                              as ther were so many variables in the program..
                              instead of writing code for every variable like

                              if(strings[0].equals("redfai l"))
                              redfail = strings[1].equalsIgnoreCa se("true") ? true:false;
                              if(strings[0].equals("redsef ail"))
                              redsefail=strin gs[1].equalsIgnoreCa se("true") ? true:false;
                              .
                              .
                              is there any other option to make strings[0] in the above code can be used directly as a variable.
                              That's the way to do it. If you have too many boolean variables why not use an array?

                              Comment

                              Working...