javascript - Doing assignment in VBscript now.. Need to give positions of each "e" in a string -


i've done in javascript needless can't swap over.

in jscript used this:

 var estr = tx_val  index = 0  positions = []   while((index = estr.indexof("e", index + 1)) != -1)  {      positions.push(index);  }  document.getelementbyid('ans6').innerhtml = "locations of 'e' in string are: "  + positions; 

i tried using same logic vbs terms, ie join, tried using instr. i'm not sure how yank out 'e'... maybe i'll try replacing character.

here tried vbscript. tried using instr , replace yank out first occurance of 'e' in each loop , replace 'x'. thought maybe make next loop through give location of next 'e'. -- when don't subscript out of range 'i' error, 1 location script , 0.

(6) show location of each occurence of character "e" in string "tx_val" in span block id="ans6"

countarr = array() countarr = split(tx_val) estr = tx_val outhtml = "" positions = array() i=0 each word in countarr i= i+1 positions(i) = instr(1,estr,"e",1) estr = replace(estr,"e","x",1,1)  next  document.getelementbyid("ans6").innerhtml = "e located at: " & positions 

what can simpler , works? , thank in advance, lot.

edit again: got working right. i'm not 100% how. ran through logic in head few dozen times before wrote , after few kinks works.

 local = ""  simon = tx_val  place=(instr(1,simon,"e"))  i=(len(simon))  count = tx_val   local = (local & " " & (instr((place),simon,"e"))) place = instr((place+1),simon,"e") count = (instr(1,simon,"e"))  loop while place <> 0   document.getelementbyid("ans6").innerhtml= local 

instr has different parameters indexof:

instr([start, ]string, searchvalue[, compare]) 
  • start: index @ start searching
  • string: string search
  • searchvalue: string search for

also note visual basic indexes strings beginning @ 1 input , return index values 1 more original javascript.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -