Click here to Skip to main content
14,237,810 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All!

I have one problem, please suggest.
CString str = _T("CodeProject\Application");

int l_Temp = str.FindOneOf(_T("/\?<>|:*")); //I'm searching for all these characters

if(l_Temp != -1)
{
  AfxMessageBox(_T("Invalid Name"));
}

It is able to searching all characters, but '\' is not searching.

Please do the needful.

Thanks
Sam
Posted
Updated 26-Feb-13 1:45am
v2
Comments
Philippe Mori 27-Feb-13 19:21pm
   
By the way, you should also have a double backslash in CodeProject\\Application.
Rate this:
Please Sign up or sign in to vote.

Solution 1

The backslash (\) must be followed with a second backslash (\\) when it appears within a string, see Escape Sequences[^]

In your case there need to be three backslash in the string, two for the backslash itself and one for the question mark (?).
int l_Temp = str.FindOneOf(_T("/\\\?<>|:*"));
   
Comments
Mr Sam 26-Feb-13 9:33am
   
Thank You so much! my problem got solved :-)
nv3 26-Feb-13 9:51am
   
Then please click Accept on the solution that has helped you ;-)
Mr Sam 27-Feb-13 7:16am
   
Oh! Sorry, i forgot. Thank you!
Rate this:
Please Sign up or sign in to vote.

Solution 2

use '\\' not '\'
ex:-
if(csProfilename.FindOneOf(L"\\/:?<>\"|")!=-1)
   
Comments
Mr Sam 27-Feb-13 7:17am
   
Thank you!
Rate this:
Please Sign up or sign in to vote.

Solution 3

use '\\' instead of '\'

:) happy to help
   
Comments
Mr Sam 27-Feb-13 7:17am
   
Thank You!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100