• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regex needed?

 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


rahul.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i have checked, i want to be printed.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) {

}
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic