Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Replace function

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Replace function

    Hey guys, Im quite new to Java and I do try to learn a bit and try to solve it by myself and I came across this questions regarding replacement strings. Can you guys help me with that please

    So here is the question:-

    The global replace function is a string-processing algorithm found in every word processor. Write a method that takes three String arguments: a document, a target string, and a replacement string. The method should replace every occurrence of the target string in the document with the replacement string.

    So, basically it needs to find a target string where the user put the sentence in and the user input the word that want to be replace and input what to change the word into.

    And here is the code I try and I couldn't figure it out

    public class Question1 {
    public static void Document(){

    }

    public static final String targetString(String str){
    str.matches(regex);
    }

    public static void replacementString(char oldString, char newString){
    oldString =
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Replace function

    public static void replacementString(char oldString, char newString){
    A problem with the variables in that code is the a char is not a String. It is a single character. So oldString is not a String, it is a single character.

    I couldn't figure it out
    What is the replacement method supposed to do? Add some comments to the code describing what it is supposed to do. It is important that the description be in the code so that they are there when the code is being read.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Delete the post
    By ssole in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 22nd, 2019, 10:56 AM
  2. Need help with replace function
    By sith in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2019, 05:31 PM
  3. How to replace the unicodes in java using keytyped or keypressed function
    By Mian Wahab in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 24th, 2017, 04:44 PM
  4. Replace bracket
    By marcobelli in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 4th, 2013, 12:00 PM
  5. Using the replace method?
    By jean28 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 22nd, 2012, 04:17 PM