Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT

Technical Article => Programming =>  C++

C++ : string beginWith and endWith

  Peter      2012-08-31 06:53:44      4,386    0    0

C++ is an very powerful programming language. It is efficient and flexible. When writing C++ programs, we may often need to process strings and often we need to check whether a string begin with some substring or end with some substring. We can use following functions to ahieve these:

    static bool beginWith(const std::string str,const std::string needle){
        return (!str.compare(0,needle.length(),needle));
    }

    static bool endWith(const std::string str,const std::string needle){
        if (str.length() >= needle.length()) {
            return (0 == str.compare (str.length() - needle.length(), needle.length(), needle));
        }
        return false;
    }

C++ BEGINWITH ENDWITH

  SAVE AS PDF   MARK AS READ   MARK AS IMPORTANT

Share on Facebook  Share on Twitter  Share on Google+  Share on Weibo  Share on Reddit  Share on Digg  Share on Tumblr    Delicious

  RELATED


No related articles

  0 COMMENT


No comment for this article.


  WRITE ARTICLE

abc.wtf Bing

By sonic0002
When you type abc.xyz, you will see the homepage of Alphabet, the new parent company of Google. But what if you type abc.wtf in your browser address bar? Go and give a try and don't forget to give us a like.