ASP NEWBIE

B

Barney

im trying to create a page that when characters are entered into a text box (ex: bobby), print out on the resulting page where only one letter of each kind is displayed (ex: boy for bobby)
 
T

TomB

Page1.htm

<form method=post action=Page2.asp>
<input name=theCharacters><input type=submit>
</form>

Page2.asp

<%
Dim sTheChars
Dim arrChars()
ReDim arrChars(0)
Dim iLoop
Dim sWorkingChar

sTheChars=Trim(Request.Form("theCharacters").Value)

for iLoop= 1 to len(sTheChars)
sWorkingChar=mid(sTheChars,iLoop,1)
Call CheckIfInTheArrayAndIfNotAddIt(sWorkingChar)
next

'Now show the result
for iLoop = 0 to UBound(arrChars)
Response.write arrChars(iLoop)
next

Sub CheckIfInTheArrayAndIfNotAddIt (sChar)
Dim x
Dim bIsThere
bIsThere=false
for x=0 to UBound(arrChars)
if sChar=arrChars(x) then
bIsThere=true
end if
next
if bIsThere=false then
redim preserve arrChars(UBound(arrChars)+1)
arrChars(UBound(arrChars))=sChar
end if

End Sub
%>



Barney said:
im trying to create a page that when characters are entered into a text
box (ex: bobby), print out on the resulting page where only one letter of
each kind is displayed (ex: boy for bobby)
 
R

Ray at

Like, I think I know what you mean. If so, here's an idea:

sSomeCharacter = "jfalsdjfawaiuefh8asfasdjfnansdmna9f


Barney said:
im trying to create a page that when characters are entered into a text
box (ex: bobby), print out on the resulting page where only one letter of
each kind is displayed (ex: boy for bobby)
 
R

Ray at

Like, I think I know what you mean. If so, here's an idea:

sSomeCharacters = "kakajsjf8jakljdfalkjdf8dsfkf8hdshfkjaknmxcnvka9s"
For i = 65 To 122
sFind = String(2, Chr(i))
Do While Instr(sSomeCharacter, sFind) > 0
sSomeCharacters = Replace(sSomeCharacters, sFind, Chr(i))
Loop
Next
Response.Write sSomeCharacters

That will remove doubling up, although it may be a bit inefficient.

Oh, wait. I think you wanted unique characters. If that's the case, here's
an idea for that.



Dim oDict As Scripting.Dictionary
sSomeCharacters = "kakajsjf8jakljdfalkjdf8dsfkf8hdshfkjaknmxcnvka9s"
Set oDict = Server.CreateObject("Scripting.Dictionary")
On Error Resume Next
For i = 1 To Len(sSomeCharacters)
oDict.Add Mid(sSomeCharacters, i, 1), Mid(sSomeCharacters, i, 1)
Next

aChars = oDict.Items
Set oDict = Nothing
Response.Write Join(aChars, "")


Post back if you need explanations.

Ray at work









Barney said:
im trying to create a page that when characters are entered into a text
box (ex: bobby), print out on the resulting page where only one letter of
each kind is displayed (ex: boy for bobby)
 
R

Ray at

Sorry, I hit Ctrl+Enter while building the random string. Ignore these
posts.

Ray at work

Ray at said:
Like, I think I know what you mean. If so, here's an idea:

sSomeCharacter = "jfalsdjfawaiuefh8asfasdjfnansdmna9f


Barney said:
im trying to create a page that when characters are entered into a text
box (ex: bobby), print out on the resulting page where only one letter of
each kind is displayed (ex: boy for bobby)
 
B

Bob Barrows

Barney said:
im trying to create a page that when characters are entered into a
text box (ex: bobby), print out on the resulting page where only one
letter of each kind is displayed (ex: boy for bobby)

.... and what part are you having a problem with?
 
R

Ray at

In your script, you'd want to correct that line... Just Dim oDict. Sorry
about that.

Ray at work
 

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

Members online

Forum statistics

Threads
474,138
Messages
2,570,799
Members
47,347
Latest member
RebekahStu

Latest Threads

Top