• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regex needed?

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rauhl Roy:
...there does not seem to be method for concatnation.

The + operator is overloaded to concatenate Strings.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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


rahul.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i have checked, i want to be printed.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic