Regular expression!!!
-
HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
something like this ?? :rolleyes:
(3 [1 [(2 0 3) | (4 [(0 1) | (1 2)])] | (2 1 1 0) | (4 2 3 2)])
You don't know where to start ? ask a good friend
-
HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
Could you possibly employ the use of a FSM?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Could you possibly employ the use of a FSM?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
DavidCrow wrote:
Could you possibly employ the use of a FSM
there is only one FSM. and he works for nobody.
-
HI All, I have a string. In this string I want to validate that if and only if the previous character is something then the next character should also follow a definite pattern. For ex: A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232. I have tried solving the issue with a lots of if's, else if's etc. but I somewhere feel that this may not be the right way to validate the input. Can somebody put some light on this issue or point me to some article link that may help me to the resolution of the problem..... Thanks in advance
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
_AnShUmAn_ wrote:
A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232.
I'm missing one value. I guess the correct entries should be 31203,
31401,
31412,32110,34232. Am I right? Further: 1. The underscore characters, are they present in the string? 2._AnShUmAn_ wrote:
A_____B______C_____D_____E
Does this line have any significance, or did you just put it there for clarification?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
_AnShUmAn_ wrote:
A_____B______C_____D_____E 3_____1______2_____0_____3 _____________4_____0_____1 ___________________1_____2 ______2______1_____1_____0 ______4______2_____3_____2 so as explained in the table above the valid entries should be 31203,31412,32110,34232.
I'm missing one value. I guess the correct entries should be 31203,
31401,
31412,32110,34232. Am I right? Further: 1. The underscore characters, are they present in the string? 2._AnShUmAn_ wrote:
A_____B______C_____D_____E
Does this line have any significance, or did you just put it there for clarification?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
kakan wrote:
I'm missing one value
I just gave a few examples about how the values could be entered by the user. Yes what you is correct.
kakan wrote:
The underscore characters, are they present in the string?
NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.
kakan wrote:
A_____B______C_____D_____E
I just put this line for clarification.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
kakan wrote:
I'm missing one value
I just gave a few examples about how the values could be entered by the user. Yes what you is correct.
kakan wrote:
The underscore characters, are they present in the string?
NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.
kakan wrote:
A_____B______C_____D_____E
I just put this line for clarification.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
OK, one more question: The "shorter" lines, are they left justified, or are they padded with blanks?
Like this (padded with blanks): "31203" " 401" " 12" " 2110" " 4232" Or like this (left justified): "31203" "401" "12" "2110" "4232"
I'm working on a solution. -- modified at 1:43 Tuesday 7th November, 2006 -- modified at 1:44 Tuesday 7th November, 2006 Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson -
kakan wrote:
I'm missing one value
I just gave a few examples about how the values could be entered by the user. Yes what you is correct.
kakan wrote:
The underscore characters, are they present in the string?
NO the underscore signs are not present in the string. I just entered them to show the alignment to the codeproject member's.
kakan wrote:
A_____B______C_____D_____E
I just put this line for clarification.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func:
void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. }
The main:CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232"
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson -
Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func:
void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. }
The main:CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232"
Alcohol. The cause of, and the solution to, all of life's problems - Homer SimpsonThanks for your time and effort both in helping me to find out the solution. I will give it a try and let you know if there is still some problem that needs to be dealt with. Thanks once again.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Thanks for your time and effort both in helping me to find out the solution. I will give it a try and let you know if there is still some problem that needs to be dealt with. Thanks once again.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
Your'e welcome, I'm glad if I can be of assistance to you. And I can't resist a challenge... Probably, there are things that must be fixed, this is a quick hack. But I think the main idea works. Good luck. Kakan
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
Hello again. I didn't receive an answer to my last question, but I made a solution that covers both cases. You will have to adjust the code for Unicode if you want it. And possibly adjust the code to ATL/STL if you want it. Here goes: The func:
void get(CString csIn, CString &csOut) { static CString csLast = ""; int lastLen = csLast.GetLength(); // Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0); int inLen = csIn.GetLength(); if(inLen >= lastLen) { // New, bigger value, save it. csLast = csIn; lastLen = csLast.GetLength(); } int copyChars = lastLen - inLen; if(copyChars > 0) { csOut = csLast.Left(copyChars); } else csOut = ""; csOut += csIn; csLast = csOut; // Save the last value for next time. }
The main:CString csRet; get("31203", csRet); // csRet becomes "31203" get(" 401", csRet); // csRet becomes "31401" get(" 12", csRet); // csRet becomes "31412" get(" 2110", csRet); // csRet becomes "32110" get(" 4232", csRet); // csRet becomes "34232"
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpsonkakan wrote:
// Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0);
What's wrong with
CString::TrimLeft()
?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
kakan wrote:
// Ignore and remove leading blanks in csIn. while(csIn.GetAt(0) == ' ') csIn.Delete(0);
What's wrong with
CString::TrimLeft()
?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb