Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Validation on characters having multiple section in a string

Validation on characters having multiple section in a string

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #1

    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

    P G 2 Replies Last reply
    0
    • N nitin_ion

      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

      P Offline
      P Offline
      Peter Leow
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • N nitin_ion

        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

        G Offline
        G Offline
        Garth J Lancaster
        wrote on last edited by
        #3

        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'

        1 Reply Last reply
        0
        • P Peter Leow

          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.

          N Offline
          N Offline
          nitin_ion
          wrote on last edited by
          #4

          how to read character from a particular position to a particular position in REGEX

          D 1 Reply Last reply
          0
          • N nitin_ion

            how to read character from a particular position to a particular position in REGEX

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups