File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to delete duplicate characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to delete duplicate characters" Watch "How to delete duplicate characters" New topic
Author

How to delete duplicate characters

Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Hey so big test tomorrow, worth like 15% of final grade and I was doing some study on past papers and one of the questions asks to convert all words into stem words. A stem word is produced from a suspect word by first removing all characters except for consonants. Then all duplicate letter sequences are removed. The Stem word for "Viagra" would be "vgr and the stem word for "vla-grrra" is also "vgr".
This is what I'v done so far


Any help would be great
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 635
what has it to do with webservices?


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Praful Thakare wrote:what has it to do with webservices?

Sorry had no idea its meant to be a java question, I just joined
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I moved the thread to "Beginning Java".
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Paul Clapham wrote:I moved the thread to "Beginning Java".

Thanks!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Sara Lyons wrote:
//this loop doesnt really work and I don't know what to do after the if statement
//im trying to delete duplicate characters in this loop and if statement but not really sure how to go about it
...Any help would be great

Before you even write a line of code, you need to stop and think about how you do things.

Think about it in English - not Java. If I gave you a piece of paper with a string of characters on it, how would YOU remove duplicate characters?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1



Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
fred rosenberger wrote:
Sara Lyons wrote:
//this loop doesnt really work and I don't know what to do after the if statement
//im trying to delete duplicate characters in this loop and if statement but not really sure how to go about it
...Any help would be great

Before you even write a line of code, you need to stop and think about how you do things.

Think about it in English - not Java. If I gave you a piece of paper with a string of characters on it, how would YOU remove duplicate characters?

Emm I'd cross them off the paper?? I'm so bad at java epic fail tomorrow .
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Sai Hegde wrote:


THANK YOU SO MUCH!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Sara, is it possible that you might be asked to explain that solution? Because I have the feeling that you don't completely understand it. If that happened, then you might be in trouble for plagiarism. And it's not a beginners technique that you've been given there, so using it might well cause the examiners to become suspicious.

Unless the rules for your exam specifically allow you to get help from other people, that is. In that case you would be in the clear.
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Paul Clapham wrote:Sara, is it possible that you might be asked to explain that solution? Because I have the feeling that you don't completely understand it. If that happened, then you might be in trouble for plagiarism. And it's not a beginners technique that you've been given there, so using it might well cause the examiners to become suspicious.

Unless the rules for your exam specifically allow you to get help from other people, that is. In that case you would be in the clear.


No it's no problem if I get help, sure my lecturers always saying when your stuck ask anyone but if this was an assignment then it would be a different story.
No I didn't really understand what ("(\\w)\\1+", "$1") and ("\\P{L}", "") mean in "String enter3= enter2.replaceAll("(\\w)\\1+", "$1")" and "String enter1 = enter.replaceAll("\\P{L}", "")".
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18840
    
  40

Sara Lyons wrote:
Paul Clapham wrote:Sara, is it possible that you might be asked to explain that solution? Because I have the feeling that you don't completely understand it. If that happened, then you might be in trouble for plagiarism. And it's not a beginners technique that you've been given there, so using it might well cause the examiners to become suspicious.

Unless the rules for your exam specifically allow you to get help from other people, that is. In that case you would be in the clear.


No it's no problem if I get help, sure my lecturers always saying when your stuck ask anyone but if this was an assignment then it would be a different story.
No I didn't really understand what ("(\\w)\\1+", "$1") and ("\\P{L}", "") mean in "String enter3= enter2.replaceAll("(\\w)\\1+", "$1")" and "String enter1 = enter.replaceAll("\\P{L}", "")".



Another issue is that you may be using a feature that you didn't learn.... In this case, using the regular expression engine when the goal of the assignment is to use loops, conditions, arrays, and assignments is not a good idea.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Henry Wong wrote:
Sara Lyons wrote:
Paul Clapham wrote:Sara, is it possible that you might be asked to explain that solution? Because I have the feeling that you don't completely understand it. If that happened, then you might be in trouble for plagiarism. And it's not a beginners technique that you've been given there, so using it might well cause the examiners to become suspicious.

Unless the rules for your exam specifically allow you to get help from other people, that is. In that case you would be in the clear.


No it's no problem if I get help, sure my lecturers always saying when your stuck ask anyone but if this was an assignment then it would be a different story.
No I didn't really understand what ("(\\w)\\1+", "$1") and ("\\P{L}", "") mean in "String enter3= enter2.replaceAll("(\\w)\\1+", "$1")" and "String enter1 = enter.replaceAll("\\P{L}", "")".



Another issue is that you may be using a feature that you didn't learn.... In this case, using the regular expression engine when the goal of the assignment is to use loops, conditions, arrays, and assignments is not a good idea.

Henry

Ye thats grand just figured out how to do it in a loop and we're already using that feature just hardly attend the lectures to know it
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

Sara Lyons wrote:Emm I'd cross them off the paper?? I'm so bad at java epic fail tomorrow .

And how would you know/decide which to cross off? What if you couldn't write on the original piece of paper, but only on a NEW piece of paper?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18840
    
  40

Sara Lyons wrote:
Henry Wong wrote:
Another issue is that you may be using a feature that you didn't learn.... In this case, using the regular expression engine when the goal of the assignment is to use loops, conditions, arrays, and assignments is not a good idea.

Henry

Ye thats grand just figured out how to do it in a loop and we're already using that feature just hardly attend the lectures to know it


Not sure if I understand what you are trying to say. Are you saying... "you figured it out using loops -- you solved it. And everything is all good"? Or are you saying ... "you just found out that you need to do it using loops -- and you can't use the previously provided solution that you don't understand"?

Henry
Sara Lyons
Greenhorn

Joined: Dec 05, 2012
Posts: 14
Henry Wong wrote:
Sara Lyons wrote:
Henry Wong wrote:
Another issue is that you may be using a feature that you didn't learn.... In this case, using the regular expression engine when the goal of the assignment is to use loops, conditions, arrays, and assignments is not a good idea.

Henry

Ye thats grand just figured out how to do it in a loop and we're already using that feature just hardly attend the lectures to know it


Not sure if I understand what you are trying to say. Are you saying... "you figured it out using loops -- you solved it. And everything is all good"? Or are you saying ... "you just found out that you need to do it using loops -- and you can't use the previously provided solution that you don't understand"?

Henry

No i figured out how to just check for duplicates using a loop. But anyway just had my test and that kind of question never came up
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to delete duplicate characters