Link to home
Start Free TrialLog in
Avatar of PMH4514
PMH4514

asked on

stripping a string from a TCHAR

I populate a TCHAR with a value from the registry:

TCHAR lpszDbPath[MSGBUFSIZ];

// registry key setup and error checking code omitted for clarity

RegQueryValueEx(hKey, _T("DBQ"), 0, &dwType, (BYTE *)lpszDbPath, &dwDataSize)) )


That gives me a value like the following in lpszDbPath

e:\MyDatabase\MyDB.mdb

what's the TChar way to strip the 'MyDB.mdb' from that result"?

thanks
Avatar of Axter
Axter
Flag of United States of America image

You can use _tcsrchr, to do a reverse search for the back slash character, and set the result to zero.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you don't want to include the back slash character in the stripping, set position one of the result to 0.

TCHAR * pos = _tcsrchr(lpszDbPath, '\\');

if (pos)
  pos[1] = 0;
Avatar of PMH4514
PMH4514

ASKER

I'm not sure I understand how that works..

when lpszDbPath = "e:\MyDatabase\MyDB.mdb"

and I execute:
TCHAR * pos = _tcsrchr(lpszDbPath, '\\');

pos ends up equal to "\MyDB.mdb"

I want pos = "E:\MyDatabase\"

Avatar of PMH4514

ASKER

oh wait, sorry Axter.. duh.. I gotta loop it.. nevermind :)