Template Maintenance-Template parsing

Source: Internet
Author: User

The parsing of the template is mainly about the parsing of the main template.

First of all, the business logic, first click on the tree node, the tree code to pay the material code, and then through the material code to query the main template (including the main template ID and main template information) and sub-template (without {} information);

If there is information in the form of {}, we pay the main template ID and the main template information to the string parameter to the foreground. In the foreground, first determine whether the string parameter passed is empty, if it is empty, it means that there is no master template, otherwise the child template information is loaded.


To parse the main template:


The first step:

The main template information obtained from the above logic is {: diesel locomotives, 0; electric locomotives, 1; passenger cars, 2; wagons, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;} This form of data.

Step Two:


We split it.
Define a DataTable and assign it two fields: an ID, a name.


Step Three:


        cut string, first two characters {: Delete   method as follows: Substring (2 , smatlcate.length-2)

        string becomes     Diesel locomotives, 0; electric locomotives, 1; passenger cars, 2; wagons, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;} &NBSP

        Then we'll remove the last}   method as follows:. Split ('} ') [0]. Trim ()  
 
        string becomes     diesel locomotive , 0; electric locomotive, 1; passenger car, 2; lorry, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;
 
        We'll take the final semicolon, and remove the   method as follows: TrimEnd (';')
 
        strings become     diesel locomotives, 0, electric locomotives, 1, passenger cars, 2, trucks, 3, EMU, 4, scrap, 5, other obsolete supplies, 9

Span style= "White-space:pre" > step three:


So we can do array conversions: string[] Strarr = Smatlcate.split (';') This is an array conversion with a semicolon bit delimiter

Fourth Step:
Finally, we can make a loop assignment for the previously defined DataTable (with two lots) in the following way:


DataRow dr = Dt_childtemplets.newrow ();
dr["ID"] = Strarr[i]. Split (', ') [1]. Trim ();
dr["NAME"] = "series:" + Strarr[i]. Split (', ') [0]. Trim () + "," + strarr[i]. Split (', ') [1]. Trim ();

Finally, we succeeded in uploading the information from the array to the DataTable.


The DT and drop-down lists are data-bound and can be assigned values.


There will also be posts for child template parsing and template testing.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Template Maintenance-Template parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.