Hi all, I'm using VS2008 with C++98. I would like to find the differences between 2 given string, extract and store them.
For example,
String A:
Box 1 is pulled with 20.1N force. Mass is 2kg and friction constant between the surfaces is k=0.4.
String B:
Box 1 is pulled with %dN force. Mass is %d%s and friction constant between the surfaces is k=%f.
The String A and B are come in a pair and the string could be different.
How can I use String B to compare with String A, and get the result
20.1
;
2kg
;
0.4
and store them in array/vector?
Any idea or algorithm that suitable for this??
Thanks.
----------------------------------------
Edited:
Hope this explain well.
1. Pass in a string as String_A
2. Find the string in front the 1st delimiter(e.g. %d) of String B in
vectorData
3. Crop the string in front the 1st delimiter as StringCrop_B, saved the
string position
4. Find StringCrop_B in String_A
5. If StringCrop_B exist in String_A, crop String_A by using
string position and declare as StringCrop_A
6. If StringCrop_B equal to StringCrop_A
7. Start to extract the differences
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
CString String_A = str_WindowCaption;
CString String_B;
CString StringCrop_A;
CString StringCrop_B;
int init = 0;
int strA_pos = 0;
int strB_pos = 0;
for(UINT i=0; i<vectorData.size(); i++) {
String_B = vectorData[i];
strB_pos = String_B.Find(_T("%s"));
if (strB_pos == -1) {
strB_pos = String_B.Find(_T("%d"));
if (strB_pos == -1) {
strB_pos = String_B.Find(_T("%f"));
if(strB_pos != -1) {
StringCrop_B = String_B.Mid(init, strB_pos-init);
}
}
}
strA_pos = String_A.Find(StringCrop_B, init);
if (strA_pos != -1){
StringCrop_A = String_A.Mid(strA_pos, strB_pos-strA_pos);
}
if (StringCrop_B == StringCrop_A) {
// do stuff
}
}
|