Check if a word is a substring of another string

Source: Internet
Author: User

Suppose a method issubstring. You can check whether a word is a substring of another string. Given two strings of S1 and S2. Write code to check if S2 is rotated S1, requiring only one issubstring to be called. (for example, Waterbottle is the string after the Erbottlewat rotation)

The above analysis is the solution to this problem: Call Issubstring directly (S1S1,S2).

BOOL Isrotation (string s1, string s2)
{
int len = S1.length ();
/* check if S1 and S2 are equal and not empty */
if (len = = S2.length () && len > 0)
{
/* stitching S1 and S2 into a new string */
String s1s1 = S1 + s1;
Return issubstring (S1S1, S2);
}
return false;
}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Check if a word is a substring of another string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.