Name: alias_neo Date: November 21, 2007 at 10:54:34 Pacific Subject: VB script help? OS: Windows Vista x64 Ultimat CPU/Ram: AMD Athlon X2 4600+, 2x C Model/Manufacturer: Built by Moi.
Comment:
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.length
Do 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 Loop
The 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.
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 Function
Then, 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.
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-1
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.
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
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE