Thread: Removing subString from String

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Removing subString from String

    Hi guys, I'm wondering how could I improve my code in terms of "concept" to solve the problem in optimal way and in creative concept.
    for example if I have string "that there at there" and substring is "th" then the output is removing from string the substring "th", i.e the output in this case is "at ere at ere" .
    what I'm thinking about is like this:
    I find the length of substring lets assume it's 2 in my upper example,
    and then simultaneously I run on the "string" itself which increasing and jumping i by two, whenever I arrive to char which isn't found on substring then I put it into another array , at the end I print the "another" array which I was modifying.
    I guess that's bad thinking and it's a pleasure by you guys to hear your ideas for solving my problem.

    by the way I'm not requiring to code a code instead of me, just need from ya clearing out your concept of how you solve that problem.


    thanks in advance.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,244
    Before you come here to ask for improvements to your algorithm:
    1. Implement your algorithm.
    2. Test it thoroughly.
    3. Revise your algorithm accordingly.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by laserlight View Post
    Before you come here to ask for improvements to your algorithm:
    1. Implement your algorithm.
    2. Test it thoroughly.
    3. Revise your algorithm accordingly.

    but i already declared my concept?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,456
    but i already declared my concept?
    So? That is only the first step, now you need to prove your concept is correct by implementing your algorithm, testing your algorithm thoroughly, and repeating the previous steps until it is correct.

  5. #5
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    He is so obviously a troll. How can you not see that? Why do you keep feeding him? Just let him die.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,532
    Already solved.
    Slicing's string concept.

    I'll keep closing anything you post which is a duplicate of anything you posted in the past.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. removing a substring from a string
    By aysek8 in forum C Programming
    Replies: 7
    Last Post: 11-05-2011, 01:22 PM
  2. Substring of a string
    By LotusE in forum C Programming
    Replies: 2
    Last Post: 01-23-2006, 03:36 PM
  3. substring in string
    By kenni81 in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:05 PM
  4. breaking string into substring
    By sadat in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 06:03 AM
  5. seeing if there is a substring in another string
    By canine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2001, 04:43 AM

Tags for this Thread