954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Removing Characters from a String

Never done this successfully before and can't seem to figure it out... Any help appreciated.

Basically this code draws my Winamp Track like this;
"Song Title - Song Artist - Winamp 0:00/0:00"
I would like to remove the - Winamp from the drawing if possible, any pointers or code would be appreciated.

#include <windows.h>
#include <stdio.h>

void PatchCall(DWORD dwAddr, DWORD dwFunc, DWORD dwLen);
#define INST_CALL 0xE8

int GetMaxTrackTime()
{
HWND win = FindWindowA("Winamp v1.x",NULL);
if(win)
return SendMessage(win,WM_USER,1,105);

return 0;
}

int GetCurrentTrackTime()
{
HWND win = FindWindowA("Winamp v1.x",NULL);
if(win)
return SendMessage(win,WM_USER,0,105);

return 0;
}

LPSTR GetCurrentWinampTrack()
{
static char szTitle[2048];
HWND win = FindWindowA("Winamp v1.x",NULL);
if(!win)
return "Winamp not found!";

GetWindowTextA(win, szTitle, sizeof(szTitle));
if(strlen(szTitle) <= 0)
return "No name!";

return szTitle;
}

The actual Drawing Function VOID WinampTrack()
{
int ct = GetCurrentTrackTime();
int mt = GetMaxTrackTime();

Texthook(120,500, 4,"%s; (%d:%02d/%d:%02d)",GetCurrentWinampTrack(),ct/(1000*60), (ct/1000)%60,mt/(60), (mt)%60);
}

An example I've seen elsewhere on removing it if (!strnicmp(rTitle,"- Winamp",) break;
rTitle--;

joejoe55
Newbie Poster
17 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

So the goal is to have a function like this?

string RemoveWinampFromString (string beforeRemoval)
// if given "Korn - Evolution - WinAmp -2:00 / 3:30", 
// should return "Korn - Evolution - 2:00 / 3:30"
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

exactly

joejoe55
Newbie Poster
17 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 
exactly

I think your best bet, then, is to use find from the string library, then use replace or erase (but not both - pick whichever you prefer; with replace , just replace the substring with an empty string). http://www.cplusplus.com/reference/string/string/find/
http://www.cplusplus.com/reference/string/string/erase/
http://www.cplusplus.com/reference/string/string/replace/

The links above have decent examples.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You