I need help parsing a string

daniel_mitrea_1995
Member Posts: 26
I have this connection string.
String := Eventstatus='Calculated' and ErrorCode='0000'
This string will always have this format but can differ the number of the fields and the operator (it can be 'AND' or 'OR')
How I can parse this string in order to get those fields and values and then to filter a specific record accordingly ?
I should take all the table fields and compare with the spllitted strings ?
In the end I have to filter the record with those values. For example in this case:
Rec.SETRANGE(EventStatus,'Calculated');
Rec.SETRANGE(ErrorCode,'0000');
Thank you
String := Eventstatus='Calculated' and ErrorCode='0000'
This string will always have this format but can differ the number of the fields and the operator (it can be 'AND' or 'OR')
How I can parse this string in order to get those fields and values and then to filter a specific record accordingly ?
I should take all the table fields and compare with the spllitted strings ?
In the end I have to filter the record with those values. For example in this case:
Rec.SETRANGE(EventStatus,'Calculated');
Rec.SETRANGE(ErrorCode,'0000');
Thank you
0
Best Answer
-
daniel_mitrea_1995 wrote: »Correct, but my question was about the table fields. Maybe I mispronounced it.
How do I know which table field corresponds to the splited string. Do I have to take all the fields in the table, one at a time, and compare them to the string?
or is there another solution?
Ok I see, I missed the part where you said there can be different fields in the string
There are many way's you can do it but what I would do is to split the string on AND's and OR's then Parse each field name and value. Next step would be to filter on the fields that are in the string.
ex. how I would do it
WHILE (STRPOS(String,'AND') > 0) OR (String,STRPOS('OR') > 0) DO BEGIN
//Get next field name and field value and insert into temp table
//Delete the field from the string
END;
IF TmpTable.FINDFIRST THEN
REPEAT
CASE TmpTable."My Field Name" OF
'Eventstatus' : Rec.SETRANGE(EventStatus,TmpTable."My Field Value");
'ErrorCode' : Rec.SETRANGE(ErrorCode,'0000');
END;
UNTIL TmpTable.NEXT = 0;
IF Rec.FINDFIRT THEN
Do Stuff..5
Answers
-
You can do this using COPYSTR and STRPOS, something like the following should work I would think
String := Eventstatus='Calculated' and ErrorCode='0000'
String := COPYSTR(String,1,STRPOS(String,'and') - 3);
String := COPYSTR(String,STRPOS(String,'=')+2,STRLEN(String));
0 -
Correct, but my question was about the table fields. Maybe I mispronounced it.
How do I know which table field corresponds to the splited string. Do I have to take all the fields in the table, one at a time, and compare them to the string?
or is there another solution?0 -
daniel_mitrea_1995 wrote: »Correct, but my question was about the table fields. Maybe I mispronounced it.
How do I know which table field corresponds to the splited string. Do I have to take all the fields in the table, one at a time, and compare them to the string?
or is there another solution?
Ok I see, I missed the part where you said there can be different fields in the string
There are many way's you can do it but what I would do is to split the string on AND's and OR's then Parse each field name and value. Next step would be to filter on the fields that are in the string.
ex. how I would do it
WHILE (STRPOS(String,'AND') > 0) OR (String,STRPOS('OR') > 0) DO BEGIN
//Get next field name and field value and insert into temp table
//Delete the field from the string
END;
IF TmpTable.FINDFIRST THEN
REPEAT
CASE TmpTable."My Field Name" OF
'Eventstatus' : Rec.SETRANGE(EventStatus,TmpTable."My Field Value");
'ErrorCode' : Rec.SETRANGE(ErrorCode,'0000');
END;
UNTIL TmpTable.NEXT = 0;
IF Rec.FINDFIRT THEN
Do Stuff..5 -
You did it.. again. Thank you0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions