aspose file tools*
The moose likes Beginning Java and the fly likes regex needed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regex needed?" Watch "regex needed?" New topic
Author

regex needed?

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Hi,

I want below mention method print "He There".



Please send me any coding help. Am I supposed to use regex? Because there does not seem to be method for concatnation.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Rauhl Roy:
...there does not seem to be method for concatnation.

The + operator is overloaded to concatenate Strings.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

And how about String.concat(String)??

Also, if you want to remove all occurrences, check String.replace(CharSequence, CharSequence) (Java 5 and up) and String.replaceAll(String, String). And how about String.replaceFirst(String, String)?
[ October 26, 2008: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401



i just want to remove "llo" from the "Hello there";


rahul.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

And what if the string would be "Hello hello there"? Should the result be "He hello there" or "He he there"?

Either way, have you checked those methods I have advised?
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

yes, i have checked, i want to be printed.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Well, all three methods I have given you can do that. And a combination of indexOf, substring and concat/+ can do it as well.
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that the remove string is length 1 or more. Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".

withoutString("Hello there", "llo") → "He there"
withoutString("Hello there", "e") → "Hllo thr"
withoutString("Hello there", "x") → "Hello there"



-----------


public String withoutString(String base, String remove) {

}
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
So OK, you've apparently been given a homework assignment, and are now providing us with the text of that assignment. Apparently, you're hoping that someone here will just hand you a solution.

Good luck with that.

Perhaps you might benefit from reading this.

Look, at some point you need to demonstrate that you're putting some effort of your own into this process. It's not enough to simply re-state the question. Several posters have been offering help, but you haven't shown any work of your own yet. We're happy to help, but we don't want to do all of your work for you. So talk to us. Tell us what you think about the suggestions that have been given so far. Tell us what you understand, or what confuses you. Try to be specific. Show us that you're really trying, and not just waiting for someone to offer up some code that does what you want.

Good luck.
[ October 27, 2008: Message edited by: Mike Simmons ]
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Mike,

I have done my home assignment and some of the test cases which are with case-sencitive are not passing.

thanks and regards,
rahul.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

Originally posted by Rauhl Roy:
Mike,

I have done my home assignment and some of the test cases which are with case-sencitive are not passing.

thanks and regards,
rahul.


Rob gave you the solution -- twice actually. He told you the method to use. The only thing that he didn't do was code it for you. Both times, you simply just reiterated the homework question.

There is really no more good hints that we can give you -- except to go back an re-read Rob's posts.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266
Originally posted by Rauhl Roy:
Mike,

I have done my home assignment and some of the test cases which are with case-sencitive are not passing.

thanks and regards,
rahul.


Then use the (?i) (the "case insensitive") regex-flag in front of your regex:


[ October 28, 2008: Message edited by: Piet Verdriet ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex needed?