删除字符串s1中s2出现的字符

一、思路

已知字符串 s1 s2:
string s1 = “aaskdauasdhdfhjbv”;
string s2 = “askdhjv”;

将s2的字符串单独作为一个字符,与s1的每一个字符串对比,如果都不是s2中出现的字符,用一个新字符串接收

删除字符串s1中s2出现的字符_第1张图片

void Start () {

    string s1 = "aaskdauasdhdfhjbv";
    string s2 = "askdhjv";

    string s3 = RejectString(s1,s2);
    for (int i = 0; i < s3.Length; i++)
    {
        Debug.LogError(s3[i]);
    }
}

/// 
/// 剔除重复字符串
/// 
string RejectString(string s1,string s2)
{
    string newstring = "";
    int i, j;
    for (i = 0; i < s1.Length; i++)
    {
        for (j = 0; j < s2.Length; j++)
        {
            if (s1[i] != s2[j])
            {
                continue;
            }
            else
            {
                j = 0;
                break;
            }
        }
        if (j == s2.Length)
        {
            newstring += s1[i];
        }
    }
    return newstring;
}

你可能感兴趣的:(删除字符串s1中s2出现的字符)