Check if one string is a prefix of another

前端 未结 13 873
-上瘾入骨i
-上瘾入骨i 2020-12-08 04:21

I have two strings which I\'d like to compare: String and String:. Is there a library function that would return true when passed these two strings

13条回答
  •  抹茶落季
    2020-12-08 04:38

    bool IsPrefix(const std::string& prefix, const std::string& whole)
    {
      return whole.size() >= prefix.size() && whole.compare(0, prefix.size(), prefix) == 0;
    }
    

提交回复
热议问题