Click here to Skip to main content
12,290,474 members (69,463 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C MFC
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 26-Feb-13 1:43am
Mr Sam725
Edited 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: bad
 
good
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("/\\\?<>|:*"));
  Permalink  
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: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

Solution 3

use '\\' instead of '\'

Smile | :) happy to help
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160518.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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