473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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..
Mar 2 '07 #1
15 6783
r035198x
13,262 8TB
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.
Mar 2 '07 #2
i want my applet to change dynamically according to the change in variable.
in my program, i want to retrieve a string ( "redfail=true") 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.
Mar 2 '07 #3
r035198x
13,262 8TB
i want my applet to change dynamically according to the change in variable.
in my program, i want to retrieve a string ( "redfail=true") 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
Expand|Select|Wrap|Line Numbers
  1.  if(value) { 
  2. //make changes
  3. }
  4. else {
  5. //make different changes
  6. }
  7.  
Now are you having a problem with any of this?
Mar 2 '07 #4
That's better.

Now you just get the value from the db into a boolean variable and compare with
Expand|Select|Wrap|Line Numbers
  1.  if(value) { 
  2. //make changes
  3. }
  4. else {
  5. //make different changes
  6. }
  7.  
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=true" 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==true) //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..
Mar 2 '07 #5
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  String s="redfail=true"; 
  2. String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
  3. boolean value = strings[1].equalsIgnoreCase("true") ? true:false;
  4. if(value) {
  5.  
  6. ///
  7. }
  8. else {
  9. //
  10. }
  11.  
Mar 2 '07 #6
thank u very much..
Mar 5 '07 #7
r035198x
13,262 8TB
thank u very much..
I take it you managed to get it work properly?
Mar 5 '07 #8
Thank u..
i have one doubt..
cant we change the string " redfail=true" to a
statement like redfail=true; ?

Expand|Select|Wrap|Line Numbers
  1.  boolean redfail=false;
  2. .
  3. .
  4. String s="redfail=true"; // s is retrieving from database
  5. .
  6. .
  7.  
  8. redfail==true ;//how can i change the value of redfail as true according to the 
  9.                    // result from the database? 
  10.  
Mar 5 '07 #9
r035198x
13,262 8TB
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


Expand|Select|Wrap|Line Numbers
  1.  
  2. String s="redfail=true"; 
  3. String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
  4. redfail = strings[1].equalsIgnoreCase("true") ? true:false;
  5.  
  6.  
In this case if the string is "redfail=true", then the variable redfail is assigned true otherwise it is assigned false.
Mar 5 '07 #10
hai ..........
i am jipson
i have one doute in c++
can you help me
Mar 5 '07 #11
r035198x
13,262 8TB
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.
Mar 5 '07 #12
Just give it the value of the variable value from the previous code I posted


Expand|Select|Wrap|Line Numbers
  1.  
  2. String s="redfail=true"; 
  3. String[] strings = s.split("="); //string[0] is redfail and strings[1] is true or false
  4. redfail = strings[1].equalsIgnoreCase("true") ? true:false;
  5.  
  6.  
In this case if the string is "redfail=true", 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,redsefail,greenfail,greenfail 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????
Mar 6 '07 #13
thank u..
in my program i have to retrieve so many strings at a time. i.e., there are so many variables like redfail,redsefail,greenfail,greenfail 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("redfail"))
redfail = strings[1].equalsIgnoreCase("true") ? true:false;
if(strings[0].equals("redsefail"))
redsefail=strings[1].equalsIgnoreCase("true") ? true:false;
.
.
is there any other option to make strings[0] in the above code can be used directly as a variable.
Mar 6 '07 #14
r035198x
13,262 8TB
to be clear..
as ther were so many variables in the program..
instead of writing code for every variable like

if(strings[0].equals("redfail"))
redfail = strings[1].equalsIgnoreCase("true") ? true:false;
if(strings[0].equals("redsefail"))
redsefail=strings[1].equalsIgnoreCase("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?
Mar 6 '07 #15
You can convert A string into expression without using switch case or if -else .how it is click the following link

http://adf.ly/3xnnc
Dec 1 '11 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jonas Prismesen | last post by:
Hi! I have string like this: string expr = "123/(12*3)"; And I want to actually calculate the mathematical expression in the string. Is there an easy way do it? Or do I have to extract all...
6
by: Alex | last post by:
Hi all. Well, I need some light in this simple thing I'm trying to do. I'm using the XMLHttpRequest to retrieve some data from a db via php script. The result is passed to a "results" array of...
9
by: Stefan Mueller | last post by:
I'd like to set a variable called 'FocusIsOn' if a button got the focus. Because my button is dynamically created I do it like xelement = document.createElement("input") xelement.type = "button"...
3
by: Cybertof | last post by:
Hello, I would like to return the good single value from a string value in these cases : Convert.ToSingle("23,30"); Convert.ToSingle("23.30"); // Conversion Error !!! The result should be...
5
by: VM | last post by:
If I have a string variable with a formula: string sMyformula = "3.3*5.2*5"; How can I convert this to a mathematical formula that the compiler can calculate? For all purposes, the formula in...
5
by: Paul Johnston | last post by:
Hi Just started using c# to do a task I usually use Perl to do and hit a limit in my knowledge :-) I have a program which reads from a large text file, extracts certain lines then gets a string...
4
by: Wilson | last post by:
Hello, How can i eval a string expression like String abc = ??"dt.Rows.Columns.ToString() + dt.Rows.Columns.ToString()" Thanks Wilson
2
by: parul.prasad | last post by:
How can we evaluate a string expression in if statement Linux C/C++
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
by: nuzhatjahan | last post by:
Hello, please help me .I want program written in c language or c++ to conver regular expression to quadruples and regular expression to triples. also program related with compiler construction
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.