This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Dreamweaver > April 2004 > ASP VBScript: MID problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ASP VBScript: MID problem
|
|
|
| Hi all,
I am trying to go a step further than all those functions that convert a
sentence into an array of words by creating a function that converts a
sentence into an array of letters and spaces.
I thought that looping through the sentence and using the MID function, I
could point to each letter/space in turn and add it to an array, but it
seems that I cannot use a variable as the position argument which has me
stuck in my tracks at the moment.
Anyone know what might be wrong with this:
varSentenceLength = LEN(varSentence)
letterCount = -1
DO WHILE i < varSentenceLength
letterCount = letterCount + 1
varSentenceArrayString = varSentenceArrayString & "" & Mid(varSentence,
letterCount, 1) & "" & ","
LOOP
If varSentence contains "Hello everyone", this code is supposed to produce a
string looking like this:
"H","e","l","l","o"," ","e","v","e","r","y","o","n","e",
It might not, I haven't been able to test this as yet!
I am not averse to using a different method of getting the sentence split
into an array another way, so long as each array item is a single letter or
a space, as shown above.
Any ideas?
Cheers,
Rob http://robgt.com/
Extensions: http://robgt.com/products/index.asp
Tutorials: http://robgt.com/tutorials/index.asp
Blog: http://blog.robgt.com/
| |
| D. Shane Fowlkes 2004-04-30, 5:30 pm |
| At first glance, it would seem that you could work in the InStr (In String)
to find the position of each letter.
"RobGT" <rob@lighthouseuk.removeme.net> wrote in message
news:c6thu2$fq4$1@forums.macromedia.com...
> Hi all,
> I am trying to go a step further than all those functions that convert a
> sentence into an array of words by creating a function that converts a
> sentence into an array of letters and spaces.
> I thought that looping through the sentence and using the MID function, I
> could point to each letter/space in turn and add it to an array, but it
> seems that I cannot use a variable as the position argument which has me
> stuck in my tracks at the moment.
> Anyone know what might be wrong with this:
>
> varSentenceLength = LEN(varSentence)
> letterCount = -1
> DO WHILE i < varSentenceLength
> letterCount = letterCount + 1
> varSentenceArrayString = varSentenceArrayString & "" & Mid(varSentence,
> letterCount, 1) & "" & ","
> LOOP
>
> If varSentence contains "Hello everyone", this code is supposed to produce
a
> string looking like this:
>
> "H","e","l","l","o"," ","e","v","e","r","y","o","n","e",
>
> It might not, I haven't been able to test this as yet!
> I am not averse to using a different method of getting the sentence split
> into an array another way, so long as each array item is a single letter
or
> a space, as shown above.
> Any ideas?
> Cheers,
> Rob http://robgt.com/
> Extensions: http://robgt.com/products/index.asp
> Tutorials: http://robgt.com/tutorials/index.asp
> Blog: http://blog.robgt.com/
>
>
| |
|
|
| Kindler Chase 2004-04-30, 5:31 pm |
| RobGT wrote:
> Hi all,
> I am trying to go a step further than all those functions that
> convert a sentence into an array of words by creating a function that
> converts a sentence into an array of letters and spaces.
> I thought that looping through the sentence and using the MID
> function, I could point to each letter/space in turn and add it to an
> array, but it seems that I cannot use a variable as the position
> argument which has me stuck in my tracks at the moment.
> Anyone know what might be wrong with this:
>
> varSentenceLength = LEN(varSentence)
> letterCount = -1
> DO WHILE i < varSentenceLength
> letterCount = letterCount + 1
> varSentenceArrayString = varSentenceArrayString & "" &
> Mid(varSentence, letterCount, 1) & "" & ","
> LOOP
>
> If varSentence contains "Hello everyone", this code is supposed to
> produce a string looking like this:
>
> "H","e","l","l","o"," ","e","v","e","r","y","o","n","e",
>
> It might not, I haven't been able to test this as yet!
> I am not averse to using a different method of getting the sentence
> split into an array another way, so long as each array item is a
> single letter or a space, as shown above.
> Any ideas?
Rob, I thnk you may be overthinking this one:
<%
Dim str
Dim intStrCount
Dim i
str = "C'mon Rob! Get with the program :-)"
intStrCount = Len(str)
ReDim arrRob(intStrCount-1)
For i = 0 to intStrCount-1
arrRob(i) = Left(str, 1)
str = Mid(str,2)
Next
For i = 0 To Ubound(arrRob)
Response.Write(arrRob(i) & "<br />")
Next
%>
--
kindler chase
http://www.ncubed.com
Home of SuperInvoice: The Online Invoicing Application.
Organize your billing process and impress your clients.
news://news.ncubed.com/support
n3 Support Group
| |
|
|
| Daniel Short 2004-04-30, 5:32 pm |
| > ReDim arrRob(intStrCount-1)
DOH! I forgot the minus 1...
Dan
| |
| Kindler Chase 2004-04-30, 5:32 pm |
| Daniel Short wrote:
>
> DOH! I forgot the minus 1...
>
> Dan
See what happens when you play in the cold :p
--
kindler chase
http://www.ncubed.com
Home of SuperInvoice: The Online Invoicing Application.
Organize your billing process and impress your clients.
news://news.ncubed.com/support
n3 Support Group
| |
|
|
| Daniel Short 2004-04-30, 5:32 pm |
| > Dan, what were you thinking missing the -1 off?
> Tut tut tut :):)
> LOL
I was thinking.... um.... some stuff.... about some other stuff... and
stuff.
Dan
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|