Foros del Web » Programando para Internet » Javascript »

Como hago esto? (array's)

Estas en el tema de Como hago esto? (array's) en el foro de Javascript en Foros del Web. Lo que pasa es que no quiero poner esto: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original var BuscarExpresion = [ / \bnew\b / g , ...
  #1 (permalink)  
Antiguo 14/12/2013, 12:47
Avatar de Zume  
Fecha de Ingreso: diciembre-2013
Mensajes: 10
Antigüedad: 10 años, 4 meses
Puntos: 0
Como hago esto? (array's)

Lo que pasa es que no quiero poner esto:

Código Javascript:
Ver original
  1. var BuscarExpresion = [/\bnew\b/g, /\bfor\b/g, /\bswitch\b/g, /\bcase\b/g, /\bsizeof\b/g, /\bpublic\b/g, /\breturn\b/g,
  2.               /\bif\b/g, /\belse\b/g, /\bwhile\b/g, /\btrue\b/g, /\bfalse\b/g, /\bdouble\b/g, /\btry\b/g, /\bvoid\b/g];
  3.  
  4. Texto = Texto.replaceArray(BuscarExpresion, ColorearExp);

Lo tengo así:

[HIGHLIGHT="Javascript"]
Código Javascript:
Ver original
  1. var BuscarExpresion = [new, for, switch, case, sizeof, public, return,
  2.               if, else, while, true, false, double, try, void];
  3.  
  4. Texto = Texto.RemplazarArray(/\bBuscarExpresion\b/g, ColorearExp);

quiero usar las expresiones que está en allí junto a BuscarExpresion de una manera por decirlo así "simplificada", "RemplazarArray" es una función que hice.
  #2 (permalink)  
Antiguo 14/12/2013, 13:23
Avatar de Lynxcraft  
Fecha de Ingreso: noviembre-2007
Ubicación: yecla murcia
Mensajes: 1.346
Antigüedad: 16 años, 5 meses
Puntos: 51
Respuesta: Como hago esto? (array's)

si utilizas nombre de funciones encierralas ente comillas simples

Código Javascript:
Ver original
  1. <script>
  2. var BuscarExpresion = ['new', 'for', 'switch', 'case', 'sizeof', 'public', 'return',
  3.               'if', 'else', 'while', 'true', 'false', 'double', 'try', 'void'];
  4. for(var n in BuscarExpresion )
  5. Texto = Texto.RemplazarArray(new RegExp("/\b"+BuscarExpresion[n]+"\b/","g"), ColorearExp);
  6. </script>
__________________
Sobran las ideas cuando faltan ganas de trabajar en ellas
Lynxcraft
  #3 (permalink)  
Antiguo 14/12/2013, 13:32
Avatar de Zume  
Fecha de Ingreso: diciembre-2013
Mensajes: 10
Antigüedad: 10 años, 4 meses
Puntos: 0
Respuesta: Como hago esto? (array's)

Cita:
Iniciado por Lynxcraft Ver Mensaje
si utilizas nombre de funciones encierralas ente comillas simples

Código Javascript:
Ver original
  1. <script>
  2. var BuscarExpresion = ['new', 'for', 'switch', 'case', 'sizeof', 'public', 'return',
  3.               'if', 'else', 'while', 'true', 'false', 'double', 'try', 'void'];
  4. for(var n in BuscarExpresion )
  5. Texto = Texto.RemplazarArray(new RegExp("/\b"+BuscarExpresion[n]+"\b/","g"), ColorearExp);
  6. </script>
Muchas gracias solo hay un problema xD no lo colorea, lo puse así:

Código Javascript:
Ver original
  1. var BuscarExpresion = ['new', 'for', 'switch', 'case', 'sizeof', 'public', 'return',
  2.                        'if', 'else', 'while', 'true', 'false', 'double', 'try', 'void',
  3.                'char', 'enum', 'static', 'using', 'namespace', 'unsigned', 'const', 'struct', 'break', 'continue'];
  4.  
  5. for(var n in BuscarExpresion );
  6. Texto = Texto.RemplazarArray(new RegExp("/\b"+BuscarExpresion[n]+"\b/","g"), "<span class='AZUL'>"+BuscarExpresion[n]+"</span>");

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:22.