dbTalk Databases Forums  

how do you check a string before replace

comp.databases.ms-access comp.databases.ms-access


Discuss how do you check a string before replace in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sparks
 
Posts: n/a

Default how do you check a string before replace - 04-10-2009 , 01:13 PM






I have a ton of strings I am parsing out and the only problem I have
is knowing whats a date and whats a special chr in a text field.

##/##/## is a date and so is #/#/## while bob/fred/mary is not.

so I checked and its ok for me to just replace all the non date / with
an underscore.
This way I can populate a table with the date and comment I pull out
of each memo field.

replace sounds nice but how do I check and see if the chr in front of
or behind the / is a number or a " " or a chr?

is this the best way to go?




Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: how do you check a string before replace - 04-10-2009 , 02:25 PM






sparks wrote:

Quote:
I have a ton of strings I am parsing out and the only problem I have
is knowing whats a date and whats a special chr in a text field.

##/##/## is a date and so is #/#/## while bob/fred/mary is not.

so I checked and its ok for me to just replace all the non date / with
an underscore.
This way I can populate a table with the date and comment I pull out
of each memo field.

replace sounds nice but how do I check and see if the chr in front of
or behind the / is a number or a " " or a chr?

is this the best way to go?

?IsDate("Mary")
False
? IsDate("12/1/2008")
True

So...
strVar = "Mary"
? IIF(IsDate(strVar),strVar,"_")
_
strVar = "12/1/2008"
? IIF(IsDate(strVar),strVar,"_")
12/1/2008


Reply With Quote
  #3  
Old   
Larry Linson
 
Posts: n/a

Default Re: how do you check a string before replace - 04-10-2009 , 02:52 PM



Salad's way is simpler and easier, but if you want to test character by
character, the ASCII code of a numeric character is greater than 48 and less
than 58 and the most commonly used blank/space character's ASCII code is 32.

Larry Linson
Microsoft Office Access MVP

"sparks" <sparks (AT) comcast (DOT) net> wrote

Quote:
I have a ton of strings I am parsing out and the only problem I have
is knowing whats a date and whats a special chr in a text field.

##/##/## is a date and so is #/#/## while bob/fred/mary is not.

so I checked and its ok for me to just replace all the non date / with
an underscore.
This way I can populate a table with the date and comment I pull out
of each memo field.

replace sounds nice but how do I check and see if the chr in front of
or behind the / is a number or a " " or a chr?

is this the best way to go?




__________ Information from ESET Smart Security, version of virus
signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com





__________ Information from ESET Smart Security, version of virus signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com






Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: how do you check a string before replace - 04-10-2009 , 03:04 PM



Larry Linson wrote:

Quote:
Salad's way is simpler and easier, but if you want to test character by
character, the ASCII code of a numeric character is greater than 48 and less
than 58 and the most commonly used blank/space character's ASCII code is 32.
I see that if I did
? IsDate("12/ 1/08)
it returns True

If the OP is returning a value to a Date field then
? IIF(isDate("12/ 1/08"),CDate("12/ 1/08"),null)
would work as it converts to a date or a null.

If the field was a string, then maybe
? IIF(isDate("12/ 1/08"),Cstr(CDate("12/ 1/08")),null)
would work as it removes the space by converting to a date then to a string.


Quote:
Larry Linson
Microsoft Office Access MVP

"sparks" <sparks (AT) comcast (DOT) net> wrote in message
news:lq2vt4pd3agfvujv85sijosvtc97q7ko7v (AT) 4ax (DOT) com...

I have a ton of strings I am parsing out and the only problem I have
is knowing whats a date and whats a special chr in a text field.

##/##/## is a date and so is #/#/## while bob/fred/mary is not.

so I checked and its ok for me to just replace all the non date / with
an underscore.
This way I can populate a table with the date and comment I pull out
of each memo field.

replace sounds nice but how do I check and see if the chr in front of
or behind the / is a number or a " " or a chr?

is this the best way to go?




__________ Information from ESET Smart Security, version of virus
signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com







__________ Information from ESET Smart Security, version of virus signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com





Reply With Quote
  #5  
Old   
sparks
 
Posts: n/a

Default Re: how do you check a string before replace - 04-16-2009 , 08:41 AM



The reason I had to do this by looking at each chr was they had done
something like this

01/1/06 asdfdfadfsdff/gggefe 02/2/06 adsf/adf etc
some of these memo fields had 10+ dates with comments after them
some memo fields were full

and their dates 06//02/06 and all kinds of mess like this

I made 1 fcn to check the position of an / and the previous chr to
make sure it was a number.
then if not I had to pass the string to a replace fcn to replace that
one chr with the _ if it was found to not be a date.
looping thru and chopping the string and writing a date and a comment
to the new table along with the correct ID

so I had 01/1/06 asdfdfadfsdff/gggefe 02/2/06 adsf/adf
write ID 02/2/06 adsf_adf
second pass
01/1/06 asdfdfadfsdff/gggefe
write ID 01/1/06 asdfdfadfsdff_gggefe


it was well overall it was a pain LOL




On Fri, 10 Apr 2009 13:04:29 -0700, Salad <oil (AT) vinegar (DOT) com> wrote:

Quote:
Larry Linson wrote:

Salad's way is simpler and easier, but if you want to test character by
character, the ASCII code of a numeric character is greater than 48 and less
than 58 and the most commonly used blank/space character's ASCII code is 32.

I see that if I did
? IsDate("12/ 1/08)
it returns True

If the OP is returning a value to a Date field then
? IIF(isDate("12/ 1/08"),CDate("12/ 1/08"),null)
would work as it converts to a date or a null.

If the field was a string, then maybe
? IIF(isDate("12/ 1/08"),Cstr(CDate("12/ 1/08")),null)
would work as it removes the space by converting to a date then to a string.



Larry Linson
Microsoft Office Access MVP

"sparks" <sparks (AT) comcast (DOT) net> wrote in message
news:lq2vt4pd3agfvujv85sijosvtc97q7ko7v (AT) 4ax (DOT) com...

I have a ton of strings I am parsing out and the only problem I have
is knowing whats a date and whats a special chr in a text field.

##/##/## is a date and so is #/#/## while bob/fred/mary is not.

so I checked and its ok for me to just replace all the non date / with
an underscore.
This way I can populate a table with the date and comment I pull out
of each memo field.

replace sounds nice but how do I check and see if the chr in front of
or behind the / is a number or a " " or a chr?

is this the best way to go?




__________ Information from ESET Smart Security, version of virus
signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com







__________ Information from ESET Smart Security, version of virus signature database 3999 (20090410) __________

The message was checked by ESET Smart Security.

http://www.eset.com






Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.