Results 1 to 5 of 5
Thread: manipulating a string (Urgent)
- 03-31-2009, 03:54 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
manipulating a string (Urgent)
Hi,
Please help me manipulate the following string, I am really stuck.
str= ~valveopen leak okh2 leak valveopen okh1;
in this string I want to delete those substrings that have a pair. Forexample
~valveopen and valveopen is a pair
leak and ~leak is a pair
and i want to retain those substrings that donot have pairs.so after making changes the string should be like this
str=okh2 okh1
I would really appreciate any kind of help.
-
You would be wise not to state this in your posts. Even if it is urgent to you, realize that it is not urgent to us. Many here take offense to this as it implies to them that a) the poster thinks that his post is more important than everyone else's, and b) that the poster wants to put pressure on the volunteers who come here to help on their own free time. Just a friendly word of advice.(Urgent)
Also, please post valid Java code. What you've posted are not Strings making it harder to figure out exactly what you're trying to do. You should use quotes properly for instance. Programming is an exercise in precision and the compiler is not very forgiving. You should thus be as precise as possible in your questions here. Also, what does the squiggle, "~" represent?
Good luck.Last edited by Fubarable; 03-31-2009 at 04:03 AM.
- 03-31-2009, 04:25 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
Sorry no use of urgent again.Thankyou for bringing this to my knowledge.
str="~valveopen leak okh2 ~leak valveopen okh1";
think of "~" as a negation sign....forexample "~leak" means "no leak" and "~valveopen" means "valve not open". In contrast only "leak" means that there is a leak and "valveopen" means valve is open. So basically the contradicting parts have to be removed from str. the resulting str is
str="okh1 okh2";
thanks for ur interest.
-
So will every pair have a String and its negation?
If so, there probably some regex that will solve this that is neat, efficient, and beyond my current abilities. For me, I'd probably split the String via String#split(" ") and then check iterate through the array looking for matches.
- 03-31-2009, 05:00 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 6
- Rep Power
- 0
ok I did that see my code
String regex=" ";
String [] cancel=newsent.split(regex); //newsent is the string that we are manipulating
if(cancel.length != 1){
for(int t=0; t<cancel.length; t++){
String tt=cancel[t];
if(tt.charAt(0)=='~')
g =true;
else
g=false;
for(int y=0;y<cancel.length;y++){
String uu=cancel[y];
if(g==true){
if(tt.substring(1).equalsIgnoreCase(uu)){
for(int w=0; w<cancel.length; w++){
if(cancel[w].equalsIgnoreCase(tt) || cancel[w].equalsIgnoreCase(uu)){
continue;
}
finl+=" "+cancel[w];
finl=finl.trim();
}
cancel=finl.split(regex);
t=-1;
break;
}
}
else {
if(uu.substring(1).equalsIgnoreCase(tt)){
for(int w=0; w<cancel.length; w++){
if(cancel[w].equalsIgnoreCase(tt) || cancel[w].equalsIgnoreCase(uu)){
continue;
}
finl+=" "+cancel[w];
finl=finl.trim();
}
cancel=finl.split(regex);
t=-1;
break;
}
}
}
}
}
but there is some problem with updation of cancel array..I dont know how to keep it update to the current state of newsent as it is also used in the outermost for loop.Please use the str="~valveopen leak okh2 ~leak valveopen okh1"; as a test case and try to reslove the errors.
Similar Threads
-
Manipulating XML
By JosephMConcepcion in forum XMLReplies: 2Last Post: 04-26-2009, 12:01 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
combine string[] into string like perl's join function
By tekberg in forum Advanced JavaReplies: 9Last Post: 02-23-2009, 01:05 PM -
Let eclipse warn about a semicolon after an if statement and string == string?
By foobar.fighter in forum EclipseReplies: 5Last Post: 01-11-2009, 10:12 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks