Forum Moderators: open

Message Too Old, No Replies

Seperating a string from a text box into an array of words

Seperating a string from a text box into an array of words

         

JaiGantic

6:11 am on Oct 6, 2004 (gmt 0)



Hello,

Thanks for reading this, I am stuck on something that may seem very simple to many of you, but I am new to ASP

Basically just need to take a sentence as a string variable from a text box and break it up into an array of strings of just the single words...

Eg: User enters "My name is John"

And I need to end up with an array "A" which has the values

A(0) = "My"
A(1) = "name"
A(2) = "is"
A(3) = "John"

Hopefully someone out there knows what I mean and has a moment to respond.. It would be hugely appreciated.

Jai

makeupalley

11:40 am on Oct 6, 2004 (gmt 0)

10+ Year Member



Dim strFromTextBox
Dim arrWords
Dim iWordCount,iTemp

strFromTextBox = "My name is John"
arrWords = Split(strFromTextBox," ")

iWordCount = Ubound(arrWords)
For iTemp = 0 To iWordCount
Response.Write ("A(" & iTemp & ")=" & arrWords(iTemp))
Next

mattglet

11:43 am on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to use the Split function [devguru.com].

strSentence = request.form("textboxvalue")

A = split(strSentence, " ")

A(0) will contain "My"
A(1) will contain "name"

etc.