Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++CMFC
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 Sam669
Edited 26-Feb-13 1:45am
v2
Comments
Philippe Mori at 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 at 26-Feb-13 9:33am
   
Thank You so much! my problem got solved :-)
nv3 at 26-Feb-13 9:51am
   
Then please click Accept on the solution that has helped you ;-)
Mr Sam at 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 at 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 at 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
Your Filters
Interested
Ignored
     
0 sanket saxena 355
1 Abhinav S 303
2 Sergey Alexandrovich Kryukov 299
3 OriginalGriff 225
4 thatraja 220
0 Sergey Alexandrovich Kryukov 8,497
1 OriginalGriff 4,850
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid