同时
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
最佳答案
根据您上面的评论,我假设该字符是 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 = '-';
}
关于c - 替换字符问题仍未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17122760/