#80493 - 2001-11-25 09:05 PM
Support for strings in for-each-in-next construct
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
I think even VBS doesn't support strings in the for-each-in-next construct but my gut feeling is that it would be kinda usefull (think about how handy it is to iterate over char[] arrays in C) :code:
for each $char in "hello world" ? $char next
An idea for a new UDF : code:
for each $char in CharArray("Hello World") ?$char next
Split() does something similar but can't quite be used to convert strings into char arrays ... the string needs at least some kind of delimiter between chars (anyone?) -Shawn [ 25 November 2001: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#80497 - 2001-11-26 05:10 PM
Re: Support for strings in for-each-in-next construct
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
JA good example. And I was thinking that this "new" way of viewing strings (as a collection of chars) could come in handy when scanning/parsing strings. By way of a simplistic example, is one wanted to code the "infamous" reverse a string routine, one could do this: code:
for each $char in "hello world" $reversed = $char + $reversed next
Here's the same routine, coded with a UDF: code:
for each $char in CharArray("hello world") $reversed = $char + $reversed next ?"reversed=" $reversed
exit 1
Function CharArray($String) dim $len,$i $len = len($String) $CharArray = "" if $len = 0 return endif dim $array[$len-1] for $i = 0 to $len-1 $array[$i] = substr("$String",$i+1,1) next $CharArray = $array EndFunction
-Shawn
|
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|