hey everyone in daniweb. i have a problem here.

let say i have 2 arrays one is a and second is b. how do i compare each of them and insert to new array c?

i do it like this

Dim a As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim i As Integer = 0
Dim arr(26) As Char
For Each c As Char Ina
arr(i) = c
i += 1
Next

Dim b As String = "RAHMAN"
Dim l As Integer = b.Length - 1
Dim newArray(l) As Char
i = 0
For Each c As Char In b
newArray(i) = c
i += 1
Next

the problem is i want to store in new array cArray() = 'R', 'A', 'H', 'M', 'N', 'B', 'C' ,and so on.....

how do i do this? this is for my assignments on permutation cipher program.
thanks.

how do i compare each of them and insert to new array c

You'll have to be clearer on what you are trying to do. You have a string (not an array as you stated), a, that contains "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and a string (again, not an array), b that contains "RAHMAN". How do you determine what you want to put into array (this time you are correct), c?

i am trying to store character from the string to array. let say for the first one
a(0)='a'
a(1)='b'
a(2)='c'
and so on

then the same for b
b(0)='r'
b(1)='a'
b(2)='h'
b(3)='m'
b(4)='a'
b(5)='n'

then from both array i want to create new array the contains both a + b, let say
c(0)='r'
c(1)='a'
c(2)='h'
c(3)='m'
c(4)='n'
c(5)='b'
c(6)='c'
c(7)='d'
c(8)='e'
c(9)='f'
and so on till c(25)='z'

so how i do this? there is comparison to array when there is same character then it will proceed to next character.

and what am i trying to do is the keyword substitution cipher. thanks again

You still haven't said how to combine the two strings. Why does c get "rahmn", then "bcde..."? Why not c = "rahmanabcdef...". Unless I know what the reasoning is I can't help you with the code.

what is i am trying to is c should be the combination of a and b. but c has a few condition.
if b(0) not same as a(0) then c(0) = b(0)
then it checks if b(0)=a(0) then c(0) = a(0)

but if for example character a in array already exist before, then it will not be displayed again.

that is why it should be like rahmnbcdefgijklopqstuvwxyz in array c.

what was happening it should check also for already exist character so it wont duplicate in array c.

i am in blur about this. thanks again for helping me.

Note - the following code assumes that len(b) <= len(a)

Dim a As String = "abcdefghijklmnopqrstuvwxyz"
Dim b As String = "rahman"
Dim c As String = ""
Dim ch As Char

For i As Integer = 0 To Len(a) - 1

    'If there are still chars left in b then pick a char from a (if a=b)
    'or from b (if a <> b). If there are no more chars in b then just take
    'the next char from a

    If i < Len(b) Then
	ch = IIf(a(i) = b(i), a(i), b(i))
    Else
	ch = a(i)
    End If

    'If the selected char is not already in c then add it to c

    If InStr(c, ch) = 0 Then
	c += ch
    End If

Next

MsgBox(c)

thanks for your reply. it is slmost the same as what i want.

but the output is rahmngjiklpqstuvwxyz. should the result is rahmnbcdefgijklopqstuvwxyz.

there is missing bcdef.

how do i fix this? and can you explain a bit bit how your code works?

thanks

First let's get the algorithm correct. We start by comparing a(0) to b(0). They are not equal so c gets b(0). What are the next two things to compare? Do we compare a(0) to b(1) or a(1) to b(1)? When do we increment the index into a? If we are never going to increment the index for string "a" then what is the point of comparing chars in string "a" to chars in string "b"?

oh. then is my logic got wrong. sorry. i thought it should be comparing while inserting strings to c.

so lets say if i want to do it like the output is rahmngjiklpqstuvwxyz how am i going to write the logic.

thanks again.

I'm not saying that rahmnbcdefgijklopqstuvwxyz is the wrong answer. I'm saying that if rahmnbcdefgijklopqstuvwxyz is the right answer then you will have to explain why it is the right answer. In other words, what is the algorithm you are using to generate c? If you don't know the answer to that then you can't write a program to do it.

Well then, there is my logic goes. i may have mistakes here.

but this one maybe useful. i try to find the logic from the code you gave me.
thanks.

This question has already been answered. Start a new discussion instead.