Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there, I'm trying to do something here and having a bit of a dilemma, I am trying to take 2 input boxes from a user, the first with a string, the second with a string.
The output should be the first string reversed with the characters in the second string excluded.
I have a nester Do while loop but my conditional is causing problems.
The conditional is like this:
i = string1.length
j = string2.lengthDo while i >= 0
Do while j >= 0
if string1.char = string2.char then
add char to ecluded list
Exit Do
else
output = output & string1.char
endif
j = j-1
Loop
i = i-1
LoopThe problem here is that if the char isnt in the ecluded list, it will go through and keep outputting the char until it reaches the number of chars in the eclusion list, if string 2 is 5 long, and the char isnt hte same, i will get the char output 5 times by the loop, then for hte next char and so on.
Any one got an idea of how i can fix this? Thanks.
AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE

That's not VBScript. VB.NET, maybe, but not VBScript.
The easiest way to do your comparison is from a function. The following code is untested, as I'm not near a version of VS, but it should give you an idea.
Function IsExcluded(ByVal c As Char, ByVal filter As String) As Boolean
Return = InStr(filter, c) = 0
End FunctionThen, in your main function/sub, just say If Not IsExcluded(<whatever>) Then <add to output>

My apologies, it's actually ASP.net using the scripting language of VB. (The page is an .aspx I'm not to good with the terminology since all this .net stuff.
Please ignore the way I wrote it, the way i wrote it is unrelated to the actual code, i just wanted to make it understandable without typing the whole code, call it pseudo-code if you like.
AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE

If it's pseudo code, say so!
I'd do something like this:
Function newStr(ByVal s1, ByVal s2)
For l = 1 To Len(s1)
If InStr(s2, Mid(s1, l, 1)) = 0 Then _
newStr = Mid(s1, l, 1) & newStr
Next
End Function
Just make sure you're using runat=server on the script tag. Otherwise, it'll only work with IE.EDIT: I'm an idiot. I saw ASP and not the .NET part. Ignore this code. Still, it might just work with a little modification. Who knows?

Ok, I have my string in a CharArray, how would I go about implementing that?
The variables set up are as follows:
Dim excText As String = excBox.Text
Dim nCharNum = txtBox.Text.Length
Dim xCharNum = excBox.Text.Length
Dim chArray() As Char = strText.ToCharArray()
Dim cxArray() As Char = excText.ToCharArray()
Dim i As Integer = nCharNum-1
Dim j As Integer = xCharNum-1AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE

You want to use Char arrays? It's simple enough; just use a nested For loop. You'll probably need to add a Boolean to know the results of the inner For, though.

I think that's where i went wrong, when i found the char in the exclusion list i tried to exit the loop and reset the loop counter for the internal loop, but it wouldn't work, i ket getting the non exlucded characters several times, can you explain to me exactly why the outer loop needs to know the status of the inner?
My brain is switched off atm, gonna g ive the project a break until i get some rest of my own.
AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE

Fine. Untested:
Dim addChr As Bool
For i as Integer = 0 To UBound(chArray)
addChr = True
For j as Integer = 0 To UBound(cxArray)
If chArray(i) = cxArray(j) Then
addChr = False
Exit For
End If
Next
If addChr Then newStr = chArray(i) + newStr
Next

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |