Re: Splitting a string into separate characters



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.



.



Relevant Pages

  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)
  • Re: Check for Common character sequence ( I will pay)?
    ... Do I need to return an array? ... You need to identify character sequences of 3 or more characters that appear ... in more than one string. ... and test each 3-character sequence that results. ...
    (microsoft.public.dotnet.framework)
  • Re: Check for Common character sequence ( I will pay)?
    ... Yes you are returning an array of FoundString objects. ... in more than one string. ... This means that you have to identify sequences 1 character at a time, ... Again, obviously, if the 3-character sequence doesn't match, neither will ...
    (microsoft.public.dotnet.framework)
  • Re: Grep and mv
    ... not some control character or the other ... > My silly little grep script extracts the names as ... Please post the script you used, ... >The space is not coming from within the file with this string. ...
    (comp.unix.shell)
  • Re: Desirable Usage of Fortran Modules
    ... suppose we want to cast a character array as ... A function that returns a string ... array of double precision numbers: ...
    (comp.lang.fortran)