Sign in to follow this  
chillypacman

LPCWSTR manipulation - anyone can help?

Recommended Posts

chillypacman    100
I was using strings for this but I now HAVE to use LPCWSTR (since strings don't seem to support japanese characters). What I need to do is split the filename extension from an LPCWSTR. For instance if I have LPCWSTR file = L"abc.txt" I need to take out the '.txt' at the end of it and just have L"abc". Any help would be appreciated :)

Share this post


Link to post
Share on other sites
scorpion007    118
Search backwards for the '.' character, and set it to 0. (NUL)

Use whatever string search function you want, for example wcsrchr().

EDIT: Oh yeah, btw. You're question was an oxymoron. You can't manipulate a LPCWSTR. A LPCWSTR is a constant string. I.e.

typedef const WCHAR *LPCWSTR;

You can however manipulate a LPWSTR (the same as above, but non-const).

[Edited by - scorpion007 on November 21, 2007 4:39:09 AM]

Share this post


Link to post
Share on other sites
scorpion007    118
Firstly, it doesn't return the first character, it returns a pointer to the last occurrence of a given character, or NULL if it could not be found.

Secondly, you cannot modify a string pointed to by a constant pointer. The pointer must point to a mutable string. I.e. LPWSTR is mutable, LPCWSTR is const. Notice the 'C' in the latter one.

For example, if you to get trim the extension from the string "FILE.TXT" you can do something like the following:


WCHAR str[] = L"FILE.TXT";
LPWSTR found = wcsrchr(str, '.'); // no need to use L on a single character.
if (found) *found = 0; // set *found to the NUL terminator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this