Page 1 of 1 1
Topic Options
#80493 - 2001-11-25 09:05 PM Support for strings in for-each-in-next construct
Shawn Administrator Offline
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
#80494 - 2001-11-26 12:15 AM Re: Support for strings in for-each-in-next construct
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Need a better example of how this would be useful. Using your example, the following does the same thing.
code:
 
$String="hello world"
For $Count = 1 To Len($String) Step 1
? SUBSTR($String,$Count,1)
Next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#80495 - 2001-11-26 03:28 PM Re: Support for strings in for-each-in-next construct
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, I just thought it would be kind of eloquent if KiXtart could treat strings as if they were a collection of characters ... which in a manner of speaking - they are

-Shawn

Top
#80496 - 2001-11-26 03:57 PM Re: Support for strings in for-each-in-next construct
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I didn't use char[] arrays yet ... so i can't verify if it would be useful,

the only thing my poor brain spits out right now is :

code:

;of course not working
for each $char in "0123456789"
$array[$char] = "whatever"
next

J.

_________________________



Top
#80497 - 2001-11-26 05:10 PM Re: Support for strings in for-each-in-next construct
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
J

A 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
#80498 - 2001-11-26 05:27 PM Re: Support for strings in for-each-in-next construct
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
nechoJ

! gnirts a gnisrever elpmaxe rof naem uoy ,ees I ... hhA

_________________________



Top
#80499 - 2001-11-26 05:35 PM Re: Support for strings in for-each-in-next construct
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Sehr gescheit mein Freund

Herr Shawn

Top
#80500 - 2001-11-26 11:46 PM Re: Support for strings in for-each-in-next construct
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Alas Horatio, muß ich relent diese Aufgabe..., Ich bin zu einem anderen Königreich weggetrieben worden. Ein das hast kein KiXtart, nay, aber nur WSH. Die Energien, Sagen zu sein muß ich VB-Index benutzen, um Grube minions zu steuern.

Herr NTdoc

Top
#80501 - 2001-11-27 01:54 AM Re: Support for strings in for-each-in-next construct
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Ist das ein Kixtart-basierter English-Deutsch Uebersetzer??? Grausig.

I'm voluntarily offering German-lessons!

Jens

P.S.: Damn, those Germans are everywhere

_________________________
There are two types of vessels, submarines and targets.

Top
#80502 - 2001-11-27 01:58 AM Re: Support for strings in for-each-in-next construct
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Es ist ein google gegründeter Übersetzer. Es funktioniert nicht zu gut, es?

-Shawn

it's amazing how fast some posts can go to hell-in-a-handbasket eh ? (lol) - oh well - if we can't have some fun sometimes, what's the point of it all

[ 27 November 2001: Message edited by: Shawn ]

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1636 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.051 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org