We help IT Professionals succeed at work.

stripping a string from a TCHAR

PMH4514
PMH4514 asked
on
1,621 Views
Last Modified: 2013-12-14
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
Comment
Watch Question

AxterSenior Software Engineer
CERTIFIED EXPERT

Commented:
You can use _tcsrchr, to do a reverse search for the back slash character, and set the result to zero.
Senior Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
AxterSenior Software Engineer
CERTIFIED EXPERT

Commented:
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;

Author

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\"

Author

Commented:
oh wait, sorry Axter.. duh.. I gotta loop it.. nevermind :)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.