[AccessD] Find characters in one string that are in another: wasRE: Treat string as array

Max Wanadoo max.wanadoo at gmail.com
Tue Mar 25 09:43:16 CDT 2008


Aha!  Now we get the question...

>I was trying to search for characters in a password that are also in a
"must contain" string.
>"The password must contain one 'special character' ~!@#$%^&*()_+ and the
password must contain one 'number' 1234567890.
>Given a password "The thread that went south", how do I determine if it
contains any special characters or numbers.

Whew!  Took a while to drag it out of him folks but we got there in the end.
Moral: Give JC rubbish answers, he gets frustrated, QED he posts the correct
question.  Rolls Eyes!

JC: Don't know if RegExp will solve it elegantly ;-) but worth a sly glance.

Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, March 25, 2008 12:40 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Find characters in one string that are in another: wasRE:
Treat string as array

ROTFLMAO.  

If you look back at my ORIGINAL post, there were no spaces specified.  It is
rather like the old "Whisper in the ear of the person on your left and see
what comes back in your right ear."  The more I try to explain, the worse
the results. 

>How can I turn a string into an array?  I need to iterate through the
characters of a string.

>For each char in str
>	dosomething char
>Next char

That seems like a simple enough question.

>How can I turn a string into an array?  I need to iterate through the
characters of a string.

FOR THE RECORD... I UNDERSTAND MID() QUITE WELL.

Also for the record, there were precisely TWO suggestions that indicated
that the reader had any concept of what I was asking.  One from Gustav and
the other from William.

However I would like to thank everyone for the responses.

Further for the record, I have already implemented the mid() scenario (days
ago) and solved the immediate problem which was:

I was trying to search for characters in a password that are also in a "must
contain" string.

"The password must contain one 'special character' ~!@#$%^&*()_+ and the
password must contain one 'number' 1234567890.

Given a password "The thread that went south", how do I determine if it
contains any special characters or numbers.

Of course the obvious (and much suggested) solution was mid(), which in the
end I just used.  It was fast and easy and ugly. 

I was hoping for a more elegant and readable solution

	MyArr = SomeConvFunction(strPassword)
	for each chr in MyArray
		if chr instr(cstrSpecialChars) then
			We're done so get out.
		endif
	next chr

Compare the readability of that to:

Function mStrContainsChars(strToTest As String, strCharsTestedAgainst As
String) As Boolean
Dim intPtr As Integer
Dim strChar As Variant
        
    For intPtr = 1 To Len(strToTest)
        strChar = Mid(strToTest, intPtr, 1)
        If InStr(strCharsTestedAgainst, strChar) Then
            mStrContainsChars = True
            Exit Function
        End If
    Next intPtr
End Function

I did get a pair of possible solutions (which I have not tested yet, given
that I already coded the mid() solution.

Hey Gustav... "how do I ..."

Pass it on.  ;-)

John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Tuesday, March 25, 2008 3:42 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Treat string as array

Hi A.D.

Very creative solution!

For how long time will JC chew on this dry stick? Next step is probably that
the spaces he specified originally which should not be present should be
present anyway or perhaps replaced by a tab or a white space! Lots of
options out there ...

/gustav

>>> adtp at airtelmail.in 25-03-2008 08:06 >>>
    A very concise version of Function Fn_ConvStringToArray(), using only a
single statement, is placed below. It returns an array, so that individual
characters of input string get placed in individual elements of the array.

    Note - In fact, right side of assignment statement (A) below, can be
used directly, as it is made up purely of access built-in functions.
Fn_ConvStringToArray() acts merely as a wrapper function, for sake of
convenience.

A.D.Tejpal
------------

' Code to be placed in VBA module
'================================
Function Fn_ConvStringToArray(StrInput _
                                As String) As Variant
    Fn_ConvStringToArray = _
                Split(Format(StrInput, _
                Mid(Replace(String(Len(StrInput), _
                "~"), "~", "~@"), 2)), "~")                         ' (A)
End Function
'================================

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list