Click here to Skip to main content
11,578,006 members (65,435 online)
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 1:43am
Mr Sam725
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
0 Richard MacCutchan 165
1 Peter Leow 150
2 OriginalGriff 120
3 Afzaal Ahmad Zeeshan 100
4 Frankie-C 85
0 OriginalGriff 880
1 Sergey Alexandrovich Kryukov 685
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393


Advertise | Privacy | Mobile
Web03 | 2.8.150603.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