Search in a string "concrete values" [closed]

-3

Good as you might look in a chain for a "specific value.

Ex:

var texto = "hola #que tal# mi nombre es #amigo#" ;

I want to get the string between "# #" it would be: what a friend

    
asked by Yasiel Hernández 19.04.2018 в 10:14
source

1 answer

2

Here is the solution.

var texto = "hola #que tal# mi nombre es #amigo#" ;

/// Split por espacios
var split = texto.split(' ');
var arr = [];

/// Por cad astring que contenga #, remplazar por nada, 
/// en caso de que haya dos, remplazar dos veces.
split.forEach(e => {
  if(e.indexOf('#') != -1){
    arr.push(e.replace('#', '').replace('#', ''))
  }

})

/// Unir con espacios
var finalstring = arr.join(' ');

console.log(finalstring);

/// que tal amigo
    
answered by 19.04.2018 / 10:32
source