Comparing a char to " ' "
So my code takes a user input such as
setq x '(yellow)
The first part removes 'setq ', and initializes the program to find the variable name (which will be x).
What i am working on now is to find the variable name so in this case 'x'.
Code:
public String var (String s){
if (s.length () == 0){
return "";
}else if (s.charAt(0) == ' '){
return "";
}else if (s.charAt (0) != ' '){
return s.charAt (0) + var (s.substring (1,s.length ()));
}else
return "";
}
So this returns the variables name so far.
Recall the input
setq x '(yellow)
My program removes setq , now it is
x '(yellow)
Now i want it to remove x ' and keep (yellow).
How can i do this using the same recursive technique as above?
Confused since im not sure how i can compare a character to a ' when
the actual compare statement in java uses 'a' to indicate when i want to compare to an a.
Thanks
Chuklol
Re: Comparing a char to " ' "
Quote:
how i can compare a character to a '
Have you tried using the escape character: \ when you define the character literal?
What is the (yellow)?
Re: Comparing a char to " ' "
thats just the next part of my code, it defines the objects in nodes in a linked list.
for now i have changed it to when it finds a |, so if i put \' it should work?
Re: Comparing a char to " ' "
What have you tried? Try escaping ', or look up the ascii number and use that instead.
Re: Comparing a char to " ' "
The problem with using an integer value for a character is that it reduces readability. Not everyone knows the ASCII codes.
Re: Comparing a char to " ' "
That worked, thanks Norm, for anyone else with similar problems
Code:
public String var (String s){
if (s.length () == 0){
return "";
}else if (s.charAt(0) == ' '){
return "";
}else if (s.charAt (0) == '\''){
return "";
}else if (s.charAt (0) != ' '){
return s.charAt (0) + var (s.substring (1,s.length ()));
}else
return "";
}