Connecting Tech Pros Worldwide Forums | Help | Site Map

get every 2 parts of array

Newbie
 
Join Date: Jan 2009
Posts: 2
#1: Jan 2 '09
Im trying to get every 2nd part of my array() for example..

dim arr() as string
dim words as string

words = "Hello there, My Name Is Beaver"
arr() = split(words, " ")

i want to create a loop to get the words: "There, name beaver"

so its like every 2 parts of the array()

Thankyou

Newbie
 
Join Date: Jan 2009
Posts: 2
#2: Jan 2 '09

re: get every 2 parts of array


set up a loop counter and test the loop variable using the modulus operator (%) with a value of 2. Suppose your loop variable is 'i'.

if (i % 2 ==0)
{
// this is every other element
}
Newbie
 
Join Date: Jan 2009
Posts: 2
#3: Jan 2 '09

re: get every 2 parts of array


This is visual basic?

Not javascript or java?
Newbie
 
Join Date: Jan 2009
Posts: 2
#4: Jan 2 '09

re: get every 2 parts of array


VB has a modulus operator. I think it is '%' as well.
Reply