Read string at a certain point?
-
Hello, I need to read the following two lines from a .txt file. Name John Doe Number +12345 Then I must extract "John Doe" and "+12345" and send them to an edit box. I tried using strtok() but it didn't work the way I want it to. Is there a way of starting at a particular point in the string? eg in "Name John Doe" at position 6. Thanks, Aoife /********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); char *pNext1 = ?????(bufLine1, ??); char *pNext2 = ?????(bufLine2, ??); strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); SendDlgItemMessage(IDC_BOX1, EM_REPLACESEL, FALSE, (LPARAM)bufLine1); SendDlgItemMessage(IDC_BOX2, EM_REPLACESEL, FALSE, (LPARAM)bufLine2); fclose( stream );
-
Hello, I need to read the following two lines from a .txt file. Name John Doe Number +12345 Then I must extract "John Doe" and "+12345" and send them to an edit box. I tried using strtok() but it didn't work the way I want it to. Is there a way of starting at a particular point in the string? eg in "Name John Doe" at position 6. Thanks, Aoife /********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); char *pNext1 = ?????(bufLine1, ??); char *pNext2 = ?????(bufLine2, ??); strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); SendDlgItemMessage(IDC_BOX1, EM_REPLACESEL, FALSE, (LPARAM)bufLine1); SendDlgItemMessage(IDC_BOX2, EM_REPLACESEL, FALSE, (LPARAM)bufLine2); fclose( stream );
Have a look at CString's Mid and Right functions. Michael :-)
-
Hello, I need to read the following two lines from a .txt file. Name John Doe Number +12345 Then I must extract "John Doe" and "+12345" and send them to an edit box. I tried using strtok() but it didn't work the way I want it to. Is there a way of starting at a particular point in the string? eg in "Name John Doe" at position 6. Thanks, Aoife /********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); char *pNext1 = ?????(bufLine1, ??); char *pNext2 = ?????(bufLine2, ??); strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); SendDlgItemMessage(IDC_BOX1, EM_REPLACESEL, FALSE, (LPARAM)bufLine1); SendDlgItemMessage(IDC_BOX2, EM_REPLACESEL, FALSE, (LPARAM)bufLine2); fclose( stream );
You can use std::string and std::ifstream like this; ifstream in ("number"); string dummy, Name, Number; in >> dummy >> Name; int >> dummy >> Number; Best regards, Alexandru Savescu
-
Hello, I need to read the following two lines from a .txt file. Name John Doe Number +12345 Then I must extract "John Doe" and "+12345" and send them to an edit box. I tried using strtok() but it didn't work the way I want it to. Is there a way of starting at a particular point in the string? eg in "Name John Doe" at position 6. Thanks, Aoife /********************************************/ FILE *stream; stream = fopen( "number", "r" ); char bufLine1[30], bufLine2[30]; fgets(bufLine1, 30, stream); fgets(bufLine2, 30, stream); char *pNext1 = ?????(bufLine1, ??); char *pNext2 = ?????(bufLine2, ??); strcpy(bufLine1, pNext1); strcpy(bufLine2, pNext2); SendDlgItemMessage(IDC_BOX1, EM_REPLACESEL, FALSE, (LPARAM)bufLine1); SendDlgItemMessage(IDC_BOX2, EM_REPLACESEL, FALSE, (LPARAM)bufLine2); fclose( stream );
If you know that the text starts in column 6, then
char *pNext1 = &bufLine1 [6];
will work just fine. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
-
If you know that the text starts in column 6, then
char *pNext1 = &bufLine1 [6];
will work just fine. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?