save the whole string into a field and use a string array to split

G

Guest

Can you show me how to use an array to split whole string in one field and
save each character in a separated array to compare to another string that
are split the same way. For example, the string is 123456789. I want to split
them like [1], [2],[3],[4]...[9] and compare with another array (split in the
same way) one by one corresponding.
thank you,
 
D

Douglas J. Steele

Dim intLoop As Integer
Dim strString As String
Dim strArray() As String*1

strString = "123456789"
ReDim strArray(1 to Len(strString))
For intLoop = 1 to Len(strString)
strArray(intLoop) = Mid(strString, intLoop, 1)
Next intLoop
 
G

Guest

Hi Expert,
Thank you for your help. That's very neat code!! Well, I have a little more
complicated issue involving to this. I need to compare the first row (record)
in the table with the rest of the records. There is a field in the first
record is the "key" to compare with others (same field name). For example,
-------------
Field 2
123456789
324435554
231998877
987771111
--------------
So, "1" in the first row will be compared with "3" in the second row. Since
"1" is diff "3", count =0, else count = 1 and the process goes on, i.e., 2
compares to 2, 3 compare to 4, and so on.

The process will repeat like that with the 1st row comparing with the 3rd
row ...
Can you show me how to do that?
Thank you,








Douglas J. Steele said:
Dim intLoop As Integer
Dim strString As String
Dim strArray() As String*1

strString = "123456789"
ReDim strArray(1 to Len(strString))
For intLoop = 1 to Len(strString)
strArray(intLoop) = Mid(strString, intLoop, 1)
Next intLoop

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Curie said:
Can you show me how to use an array to split whole string in one field and
save each character in a separated array to compare to another string that
are split the same way. For example, the string is 123456789. I want to
split
them like [1], [2],[3],[4]...[9] and compare with another array (split in
the
same way) one by one corresponding.
thank you,
 
D

Douglas J. Steele

That's a really unusual requirement!

You could write a function that accepts the two strings and returns the
count. Something along the lines of

Function CompareStrings(String1 As String, String2 As String) As Integer

Dim intCount As Integer
Dim intLoop As Integer
Dim intLen As Integer

intLen = Len(String1)
If Len(String2) < intLen Then
intLen = Len(String2)
End If

For intLoop = 1 to intLen
If Mid$(String1, intLoop, 1) = Mid$(String2, intLoop, 1) Then
intCount = intCount + 1
End If
Next intLoop

CompareStrings = intCount

End Function




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Curie said:
Hi Expert,
Thank you for your help. That's very neat code!! Well, I have a little
more
complicated issue involving to this. I need to compare the first row
(record)
in the table with the rest of the records. There is a field in the first
record is the "key" to compare with others (same field name). For example,
-------------
Field 2
123456789
324435554
231998877
987771111
--------------
So, "1" in the first row will be compared with "3" in the second row.
Since
"1" is diff "3", count =0, else count = 1 and the process goes on, i.e., 2
compares to 2, 3 compare to 4, and so on.

The process will repeat like that with the 1st row comparing with the 3rd
row ...
Can you show me how to do that?
Thank you,








Douglas J. Steele said:
Dim intLoop As Integer
Dim strString As String
Dim strArray() As String*1

strString = "123456789"
ReDim strArray(1 to Len(strString))
For intLoop = 1 to Len(strString)
strArray(intLoop) = Mid(strString, intLoop, 1)
Next intLoop

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Curie said:
Can you show me how to use an array to split whole string in one field
and
save each character in a separated array to compare to another string
that
are split the same way. For example, the string is 123456789. I want to
split
them like [1], [2],[3],[4]...[9] and compare with another array (split
in
the
same way) one by one corresponding.
thank you,
 
G

Guest

Thank you for your help. I appreciate that. Without your help, I would really
have a hard time to solve this issue. I will work on the code and let you
know when I am done.
Thank you again,
Curie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top