• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1391
  • Last Modified:

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
0
PMH4514
Asked:
PMH4514
  • 3
  • 2
1 Solution
 
AxterCommented:
You can use _tcsrchr, to do a reverse search for the back slash character, and set the result to zero.
0
 
AxterCommented:
Example:

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

if (pos)
  pos[0] = 0;
0
 
AxterCommented:
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;
0
 
PMH4514Author Commented:
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\"

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now