替换角色问题仍未解决

时间:2013-06-15 10:43:39

标签: c replace

虽然

GetWindowText(spotify_window_handle, title, title_length)

输出包含替换字符。

Spotify - Philip Glass � Glassworks Opening

我需要用“ - ”代替“ ”。我前段时间已经发布了这个问题,但是在粘贴我的代码之后就这么回答了我的回答我假设我使用了wchar_t作为标题,但我不是。标题是char *。 任何帮助都会非常感激,我对C编码是“新的”,有时候我会遇到一些基本/奇怪的行为困难。

这是我的代码:

char* spotify_title(int window_handle)
{
    int title_length = GetWindowTextLength(window_handle);
        if(title_length != 0)
        {
            char* title;
            title = (char*)malloc((++title_length) * sizeof *title );
            if(title != NULL)
            {
                GetWindowText(window_handle, title, title_length);
                if(strcmp(title, "Spotify") != 0)
            {
                return title;
            }
            else
            {
                return "Spotify is not playing anything right now. Type !botnext command to restart playback.";
            }
        }
        else
        {
            printf("PLUGIN: Unable to allocate memory for title\n");
        }
        free(title);
    }
    else
    {
        printf("PLUGIN: Unable to get Spotify window title\n");
    }
}
// End of Spotify get title function

1 个答案:

答案 0 :(得分:0)

我从上面的评论中假设该字符是0x96 = En Dash字符。

#define TITLE_PREFIX "Spotify - "
if (strncmp(title, TITLE_PREFIX, strlen(TITLE_PREFIX) == 0)
{    char *pp = strchr(title + strlen(TITLE_PREFIX), 0x96); // 0x96 = En Dash character
     if (pp != NULL)
         *pp = '-';
}