Validation on characters having multiple section in a string
-
I am reading a file and extracting a string AB01AN728930JJ7YI8 VD036583AH84000002 In this string we have differenct section like AB,01,AN728930,JJ7YI8 in one line second line has VD,036583,AH84,000002 now there will be predefined line and predefined sections in string and each section will have some common validation like length, data type etc. What is the best way of processing the validation on each character set
-
I am reading a file and extracting a string AB01AN728930JJ7YI8 VD036583AH84000002 In this string we have differenct section like AB,01,AN728930,JJ7YI8 in one line second line has VD,036583,AH84,000002 now there will be predefined line and predefined sections in string and each section will have some common validation like length, data type etc. What is the best way of processing the validation on each character set
Try regex, The 30 Minute Regex Tutorial[^] This tutorial will take you more than 30 minutes to read and understand if you are the first timer. Formulate the regex patterns according to your respective validation rules.
-
I am reading a file and extracting a string AB01AN728930JJ7YI8 VD036583AH84000002 In this string we have differenct section like AB,01,AN728930,JJ7YI8 in one line second line has VD,036583,AH84,000002 now there will be predefined line and predefined sections in string and each section will have some common validation like length, data type etc. What is the best way of processing the validation on each character set
How many variants are there on the split up of the string ? - you show two, ie, If String Starts With 'AB', then Format is AB, XX, YYYYYYYY, ZZZZZZ If String Starts With 'VD', then Format is VD, XXXXXX, YYYY, ZZZZZZ Before you go reaching for Regex, Id almost be suggesting that you look at Recursive Descent Parsing, or a parser based on a Grammar, using ANTLR perhaps - this would allow you to have rules, validation built in 'g'
-
Try regex, The 30 Minute Regex Tutorial[^] This tutorial will take you more than 30 minutes to read and understand if you are the first timer. Formulate the regex patterns according to your respective validation rules.
-
You don't. RegEx uses patterns to match against, not positions. If you know the specific positions, then you can just use the Substring method of the String class to get it. Start at this position and return x number of characters.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak