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
RobGT

2004-04-30, 5:30 pm

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/
>
>



RobGT

2004-04-30, 5:30 pm

Hi Shane,
Unfortunately, I don't want to know the position of each letter, I want to
know the letter at each position (I had the same thought last night but
realised that I need the exact opposite! :)

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:31 pm

> varSentenceLength = LEN(varSentence)
> letterCount = -1
> DO WHILE i < varSentenceLength
> letterCount = letterCount + 1
> varSentenceArrayString = varSentenceArrayString & "" & Mid(varSentence,
> letterCount, 1) & "" & ","
> LOOP


How about this instead:

Dim varSentenceLength : varSentenceLength = Len(varSentence)
ReDim arSentence(varSentenceLength)
For i = 0 to Len(varSentence)
arSentence(i) = Mid(varSentence,i+1,1)
Next

http://devshorts.com/test/letterstoarray/


--
:: Dan Short :: Take out the witty remark to reply.
Cartweaver: http://www.cartweaver.com/
Bloggin': http://blog.web-shorts.com/
Get it at da store: http://www.dwfaq.com/store/
Team Macromedia DW Volunteer: http://www.macromedia.com/go/team
Design: http://www.web-shorts.com


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


RobGT

2004-04-30, 5:32 pm

Thanks guys.
I seem to be missing a few obvious answers recently!
Argh.
I'll take my mind off work for the weekend then :)

Dan, what were you thinking missing the -1 off?
Tut tut tut :):)
LOL
Cheers,
Rob http://robgt.com/
Extensions: http://robgt.com/products/index.asp
Tutorials: http://robgt.com/tutorials/index.asp
Blog: http://blog.robgt.com/


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


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews