How to remove multiple characters from a string in C/C++

Поделиться
HTML-код
  • Опубликовано: 25 янв 2025

Комментарии • 10

  • @mochatln
    @mochatln 8 лет назад +2

    This video was very helpful and fun to follow along!! Thanks for posting! Two thumbs up

  • @vhysics
    @vhysics 7 лет назад +1

    Thanks again.Easy to grasp and remember - Brilliant!

  • @dunnowut7005
    @dunnowut7005 8 лет назад

    why use pointer rather than passing normal variable or just a refference?

    • @Programmertube
      @Programmertube  8 лет назад +1

      You maybe able to use normal variables when working with arrays or even references instead of pointers. However, pointers are usually the most complex part of C/C++ and I am hoping with enough example, I can help others understand how to use them and become comfortable using them especially that a lot of existing C/C++ code uses pointers (mainly C), so when you read code written in C/C++ you can easily understand it ;)

  • @jassonjoshua
    @jassonjoshua 8 лет назад +2

    The label of this video is misleading the actions performed in this video. This is a great video but it should be labeled as "How to remove ....... from a character in C/C++"
    I was looking for something that can actually deletes symbols from a string.
    int main ()
    {
    string s : "Hello!"
    cout

    • @Programmertube
      @Programmertube  8 лет назад +2

      string is not a basic (intrinsic) datatype in C++. It is actually a class written as part of std namespace and is not considered a basic type. strings in C/C++ are actually character arrays.
      You're looking for something like this, which I don't like :
      string str="Hello!!!!";
      std::size_t found = str.find("!");
      while (found != std::string::npos)
      {
      str.replace(found, 1, "");
      found = str.find("!");
      }
      My video shows you how to do it fine in both C/C++, so you can use my approach above, which doesn't require use of classes like std::string
      Or in my other video on removing a single char, you can do this:
      char s[] = "H!ello!!!"; //this is a string in C/C++
      int index = 0;
      for (int i = 0; i < strlen(s); ++i)
      if (s[i] != '!')
      s[index++] = s[i];
      s[index] = '\0';
      This is more efficient if you care about performance.

    • @Programmertube
      @Programmertube  8 лет назад

      The title is not misleading. I think you don't know that characters arrays that are NULL-termintaed is how you implement strings in C/C++. The string class you mentioned is not a built-in type

  • @CarleekBry
    @CarleekBry 6 лет назад

    saved my life!