scan string for characters \ / ? * : "
-
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
-
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
you can take advantage of CString. There is a member function that wil automatically remove the chars or substrings that you pass to it. I think it's called .Remove(""); You should call:
UpdateData();
editboxstring.Remove("/");From the MSDN:
CString::Remove
int CString::Remove( TCHAR ch );Return Value
The count of characters removed from the string. Zero if the string isn't changed.
Parameters
ch
The character to be removed from a string.
Remarks
Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.
Example
//remove the lower-case letter 't' from a sentence:
CString str("This is a test.");
int n = str.Remove('t');
ASSERT(n == 2);
ASSERT(str == "This is a es."); -
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
-
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
CString::Remove()
will do that, although you'll need to call it once for each character.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
you can take advantage of CString. There is a member function that wil automatically remove the chars or substrings that you pass to it. I think it's called .Remove(""); You should call:
UpdateData();
editboxstring.Remove("/");From the MSDN:
CString::Remove
int CString::Remove( TCHAR ch );Return Value
The count of characters removed from the string. Zero if the string isn't changed.
Parameters
ch
The character to be removed from a string.
Remarks
Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.
Example
//remove the lower-case letter 't' from a sentence:
CString str("This is a test.");
int n = str.Remove('t');
ASSERT(n == 2);
ASSERT(str == "This is a es.");thanks, this really helped a lot, it worked like a charm.
-
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
hobbyprogrammer wrote:
//do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters
Why not just disalloow them to begin with?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
any easy way to scan a string that a user inputs in an editbox control, for characters and remove them from the string? charachters like: \ / ? * : " < > | say i have this function... void CMyDlg::OnCheck() { GetDlgItemText(IDC_EDIT1, str); //do a scan of the string to see if it contains the characters \ / ? * : " < > | //remove them from the string //return the string without the characters MessageBox("Your string: "+str,""); } or any other way to only let the user input only a-z and A-Z characters in the editbox? thanks.
hobbyprogrammer wrote:
or any other way to only let the user input only a-z and A-Z characters in the editbox?
You can have look at http://www.codeproject.com/editctrl/enhfocusedit.asp[^] for some ideas on how to filter the input. Peace!
-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)