Write a function that compares two strings and returns a third string containing only the letters th

Posted by Pritam on Stack Overflow See other posts from Stack Overflow or by Pritam
Published on 2010-01-15T10:10:02Z Indexed on 2010/03/24 20:53 UTC
Read the original article Hit count: 956

Filed under:
|
|
|

Hi All,

I got this homework. And have solved it in following way. I need your comments whether it is a good approach or I need to use any other data sturcture to solve it in better way.

    public string ReturnCommon(string firstString, string scndString)
    {
        StringBuilder newStb = new StringBuilder();
        if (firstString != null && scndString != null)
        {
            foreach (char ichar in firstString)
            {
                if (!newStb.ToString().Contains(ichar) && scndString.Contains(ichar))
                    newStb.Append(ichar);
            }
        }
        return newStb.ToString();
    }

© Stack Overflow or respective owner

Related posts about homework

Related posts about algorithm