is there any function that can return my "Chris" where i enter "Chri" only ???
i know there is a strcmp function but it will only return mi when all the cmp of the string is the same
Printable View
is there any function that can return my "Chris" where i enter "Chri" only ???
i know there is a strcmp function but it will only return mi when all the cmp of the string is the same
#include <string.h>
char chris[5] = { "Chri" };
strcat(chris, 's');
http://msdn.microsoft.com/library/de...htm/crt3_9.asp
or
strstr()
strstr() cannot
im actually looking for a function for a search object
so if i enter a text into the edit box
it will also return mi text that is near to the one i entered.
like when i enter "chris",
it will look at my database and return mi "Chris"
There is no such standard function. You'll have to write your own string parser using strcmp. Probably work in reverse, ie: check through the DB for a match to the first initial, then check through those matches for a match to the first 2 letters, etc. etc. etc. Once you can no longer get a successful match, find the one that matches the closes to your last and return it.
Ahh, theres an example in my book about this. I can attach the files of the Derived control to my post, itt'l have all the code in it to make an autocomplete combo/edit box. Might need a little modifying though.
Oh, and here's the .h file. I couldn't attach two files to one post :(
I disagree it can be done (if he's trying to do what i think).
do you have an existing set of records that you are searching through and comparing a string to?
coz if you are then use strncmp() to compare a certain amount of letters... that should help.
U.
strstr() will work as it tests for the smaller string in the whole string
so "Chri" would return a match to "Chris", then test to see if the match is at the begining of "Chris".
roughly
Code:char *pString=NULL,sString[64]={"Chris"};
pString=strstr("Chri",sString);
if(pString!=NULL)//has matched
if(*pString==sString[0])//is at begining of string
SetDlgItemText(hWnd,ID_EDIT,sString);
thanks everyone for the help
but can i ask how to i seperate the words into parts so as i can do some coding to check for the nearest, said by jdinger
will the strstr() work for CString also novacain??
becoz i see u r using the char pointer and char array
or is there ways that i can convent the CString to char* or char[]?
- You can use the GetBuffer function to get a pointer to the object's character buffer.
- You can also change the CString with the pointer returned from GetBuffer but you need to release the buffer (ReleaseBuffer) after changing it.
- You can use the Find or the ReverseFind (only chars) function to find a substring.
Code:CString s("abcdefgd");
char *ptr = s.GetBuffer(15);
int i = s.Find('d'); /* i = 3 */
i = s.Find('d', 4); /* i = 7 (2th arg is start position) */
i = s.Find(_T("bc")); /* i = 1 */
if((ptr = strstr(ptr, "bc")) != NULL) /* ptr = "bcdefga" */
{
strcpy(ptr, "hello");
s.ReleaseBuffer(); /* s = "ahelloa" */
}
Quote:
Originally posted by Monster
- You can use the GetBuffer function to get a pointer to the object's character buffer.
- You can also change the CString with the pointer returned from GetBuffer but you need to release the buffer (ReleaseBuffer) after changing it.
- You can use the Find or the ReverseFind (only chars) function to find a substring.
Code:CString s("abcdefgd");
char *ptr = s.GetBuffer(15);
int i = s.Find('d'); /* i = 3 */
i = s.Find('d', 4); /* i = 7 (2th arg is start position) */
i = s.Find(_T("bc")); /* i = 1 */
if((ptr = strstr(ptr, "bc")) != NULL) /* ptr = "bcdefga" */
{
strcpy(ptr, "hello");
s.ReleaseBuffer(); /* s = "ahelloa" */
}
i wish to ask wat is the _T for ???
Sorry, you don't need that. It's for mapping/converting strings from Single Byte Strings to Multi Byte Strings (I think).
Just forget the _T.
Cheers, Monster