Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/04/2013, 21:07
Avatar de bryanjhv
bryanjhv
 
Fecha de Ingreso: marzo-2013
Ubicación: Cajamarca
Mensajes: 35
Antigüedad: 11 años, 8 meses
Puntos: 3
Respuesta: ¿Cómo recorrer un string y reemplazar valores?

Gracias por la respuesta, lo probé y funciona a la perfección.
A lo que me refería con reemplazar es como hacer una especie de "switch" pero trabajando con el array de arriba. Puedo hacer un bloque de if() con substr y while pero gastaría demasiado espacio y tengo mucho código en array:
Código Javascript:
Ver original
  1. var esfera = [
  2.     [
  3.         ['A',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/548635_298256880289238_993382868_n.jpg',     '298256880289238'],
  4.         ['B',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash3/598850_298256890289237_478614916_n.jpg',     '298256890289237'],
  5.         ['C',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-prn1/23872_298256900289236_1940759013_n.jpg',     '298256900289236'],
  6.         ['D',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-snc6/254254_298256926955900_1213955725_n.jpg',    '298256926955900'],
  7.         ['E',   'http://sphotos-d.ak.fbcdn.net/hphotos-ak-snc6/183813_298256943622565_742728769_n.jpg',     '298256943622565'],
  8.         ['F',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-prn1/559622_298256946955898_1573844477_n.jpg',    '298256946955898'],
  9.         ['G',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-prn1/563979_298256950289231_823991634_n.jpg',     '298256950289231'],
  10.         ['H',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/552326_298256956955897_1576081640_n.jpg',    '298256956955897'],
  11.         ['I',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash4/320374_298256966955896_1807730120_n.jpg',    '298256966955896'],
  12.         ['J',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-prn1/149843_298256976955895_849542244_n.jpg',     '298256976955895'],
  13.         ['K',   'http://sphotos-d.ak.fbcdn.net/hphotos-ak-prn1/32332_298256986955894_732974388_n.jpg',      '298256986955894'],
  14.         ['L',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/553603_298256990289227_2021539574_n.jpg',    '298256990289227'],
  15.         ['M',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-prn1/553793_298256996955893_880652486_n.jpg',     '298256996955893'],
  16.         ['N',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/581634_298257003622559_737464779_n.jpg',     '298257003622559'],
  17.         ['O',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-snc7/578406_298257006955892_1293677946_n.jpg',    '298257006955892'],
  18.         ['P',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-prn1/643877_298257043622555_1347730065_n.jpg',    '298257043622555'],
  19.         ['Q',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash4/407665_298257070289219_291228970_n.jpg',     '298257070289219'],
  20.         ['R',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash3/557785_298257093622550_1881638415_n.jpg',    '298257093622550'],
  21.         ['S',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-snc6/185018_298257110289215_1716106049_n.jpg',    '298257110289215'],
  22.         ['T',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-snc6/222447_298257116955881_1752243842_n.jpg',    '298257116955881'],
  23.         ['U',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash3/550174_298257126955880_1557061980_n.jpg',    '298257126955880'],
  24.         ['V',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-snc6/222430_298257133622546_2113165194_n.jpg',    '298257133622546'],
  25.         ['W',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-snc7/384858_298257146955878_729021692_n.jpg',     '298257146955878'],
  26.         ['X',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash4/400303_298257156955877_1783531610_n.jpg',    '298257156955877'],
  27.         ['Y',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/545364_298257160289210_1759111284_n.jpg',    '298257160289210'],
  28.         ['Z',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-snc6/269861_298257166955876_458116389_n.jpg',     '298257166955876']
  29.     ],
  30.     [
  31.         ['A',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash4/485104_511130415564974_1237921148_n.png',    '511130415564974'],
  32.         ['B',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-ash4/184888_511130425564973_1205372950_n.png',    '511130425564973'],
  33.         ['C',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-snc7/407713_511130435564972_678737091_n.png',     '511130435564972'],
  34.         ['D',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-prn1/62218_511130445564971_1925189884_n.png',     '511130445564971'],
  35.         ['E',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-prn1/604004_511130468898302_1831282194_n.png',    '511130468898302'],
  36.         ['F',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash4/482902_511130492231633_155733978_n.png',     '511130492231633'],
  37.         ['G',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-prn1/603935_511130498898299_341421741_n.png',     '511130498898299'],
  38.         ['H',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-prn1/536672_511130505564965_764405925_n.png',     '511130505564965'],
  39.         ['I',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash4/378396_511130512231631_503987318_n.png',     '511130512231631'],
  40.         ['J',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-prn1/21818_511130515564964_960014379_n.png',      '511130515564964'],
  41.         ['K',   'http://sphotos-d.ak.fbcdn.net/hphotos-ak-snc7/305606_511130522231630_1809189925_n.png',    '511130522231630'],
  42.         ['L',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/378447_511130535564962_2099806009_n.png',    '511130535564962'],
  43.         ['M',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/561517_511130565564959_882048593_n.png',     '511130565564959'],
  44.         ['N',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-snc7/374541_511130598898289_1804632177_n.png',    '511130598898289'],
  45.         ['O',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash3/533833_511130605564955_693180702_n.png',     '511130605564955'],
  46.         ['P',   'http://sphotos-d.ak.fbcdn.net/hphotos-ak-prn1/522426_511130618898287_954080016_n.png',     '511130618898287'],
  47.         ['Q',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-prn1/148144_511130625564953_2101433825_n.png',    '511130625564953'],
  48.         ['R',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-ash3/548922_511130635564952_683876059_n.png',     '511130635564952'],
  49.         ['S',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-prn1/68379_511130652231617_883537376_n.png',      '511130652231617'],
  50.         ['T',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/532257_511130658898283_417158099_n.png',     '511130658898283'],
  51.         ['U',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-prn1/558838_511130665564949_966007244_n.png',     '511130665564949'],
  52.         ['V',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash3/46182_511130682231614_1339028943_n.png',     '511130682231614'],
  53.         ['W',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/59067_511130692231613_1407293597_n.png',     '511130692231613'],
  54.         ['X',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-ash3/546909_511130702231612_1486627249_n.png',    '511130702231612'],
  55.         ['Y',   'http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash4/263537_511130708898278_569633544_n.png',     '511130708898278'],
  56.         ['Z',   'http://sphotos-g.ak.fbcdn.net/hphotos-ak-ash3/579100_511130712231611_1769538387_n.png',    '511130712231611']
  57.     ],
  58.     [
  59.         ['A',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-snc7/306004_511119865566029_389506212_n.jpg',     '511119865566029'],
  60.         ['B',   'http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash3/536476_511119875566028_1947540138_n.jpg',    '511119875566028'],
  61.         ['C',   'http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/546979_511119885566027_1976400563_n.jpg',    '511119885566027'],
  62.         ['D',   'http://sphotos-b.ak.fbcdn.net/hphotos-ak-prn1/540137_511119892232693_1232029942_n.jpg',    '511119892232693'],
  63.         ['E',   'http://sphotos-h.ak.fbcdn.net/hphotos-ak-prn1/532185_511119902232692_1641252075_n.jpg',    '511119902232692'],
  64.         ['F',   'http://sphotos-f.ak.fbcdn.net/hphotos-ak-snc6/230023_511119918899357_1698017634_n.jpg',    '511119918899357'],
  65.         ...
  66.     ]
  67. ];
Es decir, si se detectó la "A" en el string, debe reemplazarlo por "5028" (está con 'A' al comienzo del array).