Re: Splitting a string into separate characters
- From: "Michael Harris \(MVP\)" <mikhar at mvps dot org>
- Date: Tue, 7 Jun 2005 20:48:23 -0700
KAREN27 wrote:
> Hi all,
>
> Does anyone know of a VB Script that will split a string into separate
> characters.
>
> For example:
>
> 1. If I have a word stored in a variable (eg. testword).
>
> 2. Count the number of characters (which in this example would show 8
> to the user).
>
> 3. Then separate the string so each letter is then stored
> individually into an individual array item (which would be create 8
> array items) so then I can do things with each letter on its own.
>
> So if I address array item three, the letter I'm addressing is the
> letter "s".
>
> Although I think the array item '3' is actually the second character
> 'e' in VB Scripting as think it starts counting from zero.
>
Len(str) will you the length of a string (number of characters)...
Mid(str,N,1) returns the Nth character in a string...
str = "testword"
wscript.echo len(str) '==> 8
wscript.echo mid(str,3,1) '==> s
wscript.echo string(20,"=")
for n = 1 to len(str)
wscript.echo mid(str,n,1)
next
wscript.echo string(20,"=")
Download details: Windows Script Documentation
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en
--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.
.
- References:
- Splitting a string into separate characters
- From: KAREN27
- Splitting a string into separate characters
- Prev by Date: Splitting a string into separate characters
- Next by Date: Re: Splitting a string into separate characters
- Previous by thread: Splitting a string into separate characters
- Next by thread: Re: Splitting a string into separate characters
- Index(es):
Relevant Pages
|