String parser Using Regular Expression for Date format display using Locale Settings)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rahul

    String parser Using Regular Expression for Date format display using Locale Settings)

    Hey Guys

    I have a development environment, in which the whole SQL syntax is
    stored in the Database.

    So the syntax in the databse column could be

    "where BirthDate = '12/31/2005' and ID = 345"

    Note : The above string is stored and the dates are in US format. so
    the dates are displayed in mm/dd/yyyy format, so when the user
    retreives this record and shows it in the UI in textbox it would show
    what is saved in the Databse - as the above string.

    My requirement:-

    If User's PC is in British Format (UK English) Locale settings then i
    need to parse that string and display that in the UI.
    so my expected result should show

    "where BirthDate = '31/12/2005' and ID = 345"
    Note: UI should show in UK format dd/mm/yyyy


    So my idea is to parse the sting using regular expressions for date and
    convert then to Client locale setting date format and while sending the
    date back (where clause) to the databse then reconvert the string and
    save it to the database in the US format.

    The same goes for numbering system also. If the User PC is in italian
    format then
    ID = 345 should show ID = 3,45 (the way Italian format is shown).

    I know how to deal with RegEx for password , email validations but not
    to an extent of parsing and converting into a desired format.

    Any suggestions or help would be really appreciated.

    Thanks

    Rahul

  • KBuser

    #2
    Re: String parser Using Regular Expression for Date format display using Locale Settings)

    I'm still pretty new to regex so this is going to be sloppy and
    probably not the easiest way if it even works, but I would use
    something like this after you match it:
    string bdate = Regex.Match(val , "\d+/\d+/\d+").Value;
    string month = Regex.Match(val , "^\d+/").Value;
    string day = Regex.Match(val , "/\d+/")Value;
    string year = Regex.Match(val , "/\d{4}").Value;

    I'm not sure if this will work, but if it does as i intend it to,
    you'll have a separate string for each part of the date, which you can
    then order based on whichever d/t format you're working with. If this
    doesn't work (I can't try it atm as i'm working on another project,
    well, supposed to be at least) then you're going to have to make some
    substrings, let me know, and if you still need help i'll take a better
    stab at it.

    Comment

    • Rahul

      #3
      Re: String parser Using Regular Expression for Date format display using Locale Settings)

      Thanks KBUSer ,
      I would try that and let you know for sure
      Appreciate it

      Rahul

      Comment

      Working...