Click here to Skip to main content
Rate this: bad
good
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 2:43am
Mr Sam701
Edited 26-Feb-13 2: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
0 OriginalGriff 445
1 Sergey Alexandrovich Kryukov 322
2 Maciej Los 275
3 CHill60 195
4 King Fisher 179
0 OriginalGriff 240
1 Maciej Los 95
2 Sascha Lefévre 85
3 King Fisher 70
4 F-ES Sitecore 55


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2015
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