471,603 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,603 software developers and data experts.

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

Jan 27 '06 #1
2 2715
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.

Jan 27 '06 #2
Thanks KBUSer ,
I would try that and let you know for sure
Appreciate it

Rahul

Jan 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.