String Parsing
-
I have an MFC application that querries an ODBC responder. There is a particular set of messages which is unique to the system which are send to the server through the winsock to register and then to querry the ODBC. Once the application receives the data from the winsock control it is in a string which has to be parsed, right now I got the string separated by the "|" that's the symbol that separates these messages. Then, the information from the ODBC comes in this format, { 1 1 administrator Default {} {} 0 {}} I am having a hard time parsing the information out of the curly braces. I was thinking of finding the position of the first "{" brace and then finding the position of the last "}" brace, and then extracting the content in between. If any of you guys have any suggestions, methods or any sample code wchich could help me out it would be great, :-) Thanks
-
I have an MFC application that querries an ODBC responder. There is a particular set of messages which is unique to the system which are send to the server through the winsock to register and then to querry the ODBC. Once the application receives the data from the winsock control it is in a string which has to be parsed, right now I got the string separated by the "|" that's the symbol that separates these messages. Then, the information from the ODBC comes in this format, { 1 1 administrator Default {} {} 0 {}} I am having a hard time parsing the information out of the curly braces. I was thinking of finding the position of the first "{" brace and then finding the position of the last "}" brace, and then extracting the content in between. If any of you guys have any suggestions, methods or any sample code wchich could help me out it would be great, :-) Thanks
Hello, the codegurus around the world.;) I'm not sure what is going on. 1) Did you create your own client/server program? 2) If so, server program reads some info from ODBC setting on Window NT server, server program sends this info to client. 3) Did you use CSocket class or WinSock API? If you use CSocket class, we have a chance to have our class derived from CObject to set the data structure to make our life easy.:rolleyes: Have a nice day! -Masaaki Onishi-
-
I have an MFC application that querries an ODBC responder. There is a particular set of messages which is unique to the system which are send to the server through the winsock to register and then to querry the ODBC. Once the application receives the data from the winsock control it is in a string which has to be parsed, right now I got the string separated by the "|" that's the symbol that separates these messages. Then, the information from the ODBC comes in this format, { 1 1 administrator Default {} {} 0 {}} I am having a hard time parsing the information out of the curly braces. I was thinking of finding the position of the first "{" brace and then finding the position of the last "}" brace, and then extracting the content in between. If any of you guys have any suggestions, methods or any sample code wchich could help me out it would be great, :-) Thanks
Check out my CStringParser class (posted here on CodeProject). It supports "quoted" strings, but you're using matching braces, so you'd have to replace the '{' and '}' with a suitable character, like a double quote or maybe even a caret. Here's how it would work: CString sMyString = "{ 1 1 administrator Default {} {} 0 {}}"; // remove the curly brace and space characters from the beginning of the string sMyString.Mid(2); // remove the last curly brace from the end of the string sMyString.Left(0, sMyString.GetLength() - 1); // replace the braces sMyString.Replace('{', '\"'); sMyString.Replace('}', '\"'); // now parse the string CStringParser sParser(sMyString,' ', '\"'); You should get the following string values as a result: sParser.GetField(0) - "1 1 administrator Default "" "" 0 """ sParser.GetField(1) - "1" sParser.GetField(2) - "1" sParser.GetField(3) - "administrator" sParser.GetField(4) - "Default" sParser.GetField(5) - "" sParser.GetField(6) - "" sParser.GetField(7) - "0" sParser.GetField(5) - ""
-
Hello, the codegurus around the world.;) I'm not sure what is going on. 1) Did you create your own client/server program? 2) If so, server program reads some info from ODBC setting on Window NT server, server program sends this info to client. 3) Did you use CSocket class or WinSock API? If you use CSocket class, we have a chance to have our class derived from CObject to set the data structure to make our life easy.:rolleyes: Have a nice day! -Masaaki Onishi-
-
Check out my CStringParser class (posted here on CodeProject). It supports "quoted" strings, but you're using matching braces, so you'd have to replace the '{' and '}' with a suitable character, like a double quote or maybe even a caret. Here's how it would work: CString sMyString = "{ 1 1 administrator Default {} {} 0 {}}"; // remove the curly brace and space characters from the beginning of the string sMyString.Mid(2); // remove the last curly brace from the end of the string sMyString.Left(0, sMyString.GetLength() - 1); // replace the braces sMyString.Replace('{', '\"'); sMyString.Replace('}', '\"'); // now parse the string CStringParser sParser(sMyString,' ', '\"'); You should get the following string values as a result: sParser.GetField(0) - "1 1 administrator Default "" "" 0 """ sParser.GetField(1) - "1" sParser.GetField(2) - "1" sParser.GetField(3) - "administrator" sParser.GetField(4) - "Default" sParser.GetField(5) - "" sParser.GetField(6) - "" sParser.GetField(7) - "0" sParser.GetField(5) - ""