Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* estrae dalla stringa testo la prima sottostringa che inizia con s1(stringa a piacere) e termina con s2 (stringa a piacere).
  2.  
  3. Se delim==true restituisce, insieme alla sottostringa, anche i delimitatori s1 e s2, se delim==false li esclude.
  4.  
  5. Nella sequenza : .....s1....s1-----s2....s2.... restituisce s1-----s2 e non s1....s1-----s2 (restste ai "delimitatori annidati")
  6.  
  7. Se la sottostringa non viene trovata, restituisce una sottostringa vuota.  
  8.  
  9. Non utilizza regex. */
  10.  fs(testo,s1,s2,delim)
  11. {
  12.  
  13. i1=testo.indexOf(s1);
  14. if (i1>-1)
  15.    {
  16.    i1=i1+s1.length;
  17.    testo=testo.substring(i1);
  18.    }
  19. else
  20.    {testo="";return testo;}
  21. i2=testo.indexOf(s2);
  22. if (i2>-1)
  23.       {testo=testo.substring(0,i2);
  24.       }
  25. else
  26.       {testo="";return testo;
  27.       }
  28. lif=testo.lastIndexOf(s1);
  29. if (lif!=-1)
  30.    {lif=lif+s1.length;
  31.     testo=testo.substring(lif);
  32.    }
  33. if (delim)
  34.    {testo=s1+testo+s2;
  35.    }
  36. return testo;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement