Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
DeleteWord——删除某字符串中的某个字符 - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


// 删除某字符串中的某个字符
// str 原字符串
// word 欲删除的字符
//
// 处理过后的字符串直接返回到原字符串中
void DeleteWord(wchar_t str[], wchar_t word)
{
    // 临时存储修改好的字符串
    wchar_t* tempstr = new wchar_t[lstrlen(str) + 1];
    wsprintf(tempstr, L"");

    // 删除换行
    for (int i = 0, j = 0; i < lstrlen(str); i++, j++)
    {
        // 跳过换行
        if (str[i] == word)
        {
            j--;
            continue;
        }
        else
        {
            wsprintf(tempstr, L"%ls%c", tempstr, str[i]);
        }
    }

    // 将修改好的字符串复制过去
    lstrcpy(str, tempstr);

    if (tempstr != NULL)
    {
        delete[] tempstr;
        tempstr = NULL;
    }
}




返回首页


Copyright (C) 2018-2024 huidong