Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15

Discussione: operazioni su stringa

  1. #1

    operazioni su stringa

    come mostrare una stringa all'inverso?

    poi...le lettere della stringa dovrebbero uscire con un'ordine casuale!

    ciao
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    21,188
    codice:
    var strorg = "tua stringa";   // stinga di input (viene modificata)
    var strinv = "";              // stringa invertita
    var strrnd = "";              // stringa anagrammata random
    
    for (var i=strorg.length; i>0; i--) { // inversione
      strinv += strorg.substr(i-1,1);
    }
    
    while ((var m = strorg.length) > 0) { // randomizzaz.
      var j = Math.floor(Math.rand()*m);
      strrnd += strorg.substr[j,1];
      strorg = strorg.substr(0,j) + strorg.substr(j+1);
      alert ("controllo: strorg="+strorg); // da togliere dopo il debug)
    }
    Va bene una csoa cosi`?

    Non la ho provata: fallo tu per me.

    Ciao
    Michele
    Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
    No domande tecniche in messaggi privati

  3. #3
    mi spieghi cosa fanno?...le provo subito

    grazie

    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  4. #4
    no...non funziona tutto....mi da errore qui:

    function random(strorg)
    {
    var strrnd = "";
    while ((var m = strorg.length) > 0) {
    var j = Math.floor(Math.rand()*m);
    -----> strrnd += strorg.substr[j,1];
    strorg = strorg.substr(0,j) + strorg.substr(j+1);
    alert ("controllo: strorg="+strorg);
    }
    document.f.casuale.value=strrnd
    }
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    21,188
    Ecco le prove che devi fare:

    1. togliere la funzione random (in pratica tutto il ciclo while), per vedere se il resto funziona.

    2. dirmi anche che errore ti da`

    3. inserire un alert cosi`:
    codice:
    while ((var m = strorg.length) > 0) { // randomizzaz.
      var j = Math.floor(Math.rand()*m);
      alert ("j="+j+"  car="+strorg.substr[j,1]);
      strrnd += strorg.substr[j,1];
      strorg = strorg.substr(0,j) + strorg.substr(j+1);
      alert ("controllo: strorg="+strorg); // da togliere dopo il debug)
    }
    Ciao
    Michele
    Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
    No domande tecniche in messaggi privati

  6. #6
    č solo la funzione di random ke non vā...

    dā errore di sintassi e non esegue proprio lo script...ora ti posto tutto...

    codice:
    <script language="JavaScript">
    var strinv = "";
    
    function elabora()
    {
      parola=document.f.stringa.value
      document.f.lunghezza.value=document.f.stringa.value.length
      
      inverso(parola)
      random(parola)
    }
    
    function inverso(word) { 
    
    for (var i=word.length; i>0; i--) { // inversione
      strinv += word.substr(i-1,1);
    }
    document.f.inversa.value=strinv
    }
    
    function random(strorg)
    {
    var strrnd=""
    
    while ((var m = strorg.length) > 0) { // randomizzaz.
      var j = Math.floor(Math.rand()*m);
      alert ("j="+j+"  car="+strorg.substr[j,1]);
      strrnd += strorg.substr[j,1];
      strorg = strorg.substr(0,j) + strorg.substr(j+1);
      alert ("controllo: strorg="+strorg); // da togliere dopo il debug)
    }
    document.f.casuale.value=strrnd
    }
    
    </script>
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  7. #7
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    21,188
    Ha pure ragione. Il metodo si chiama Math.random() .

    Per riferimento

    E dato che random e` una funzione intrerna, magari non usarla come nome di funzione.

    Scusa
    Ciao
    Michele
    Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
    No domande tecniche in messaggi privati

  8. #8
    no...mi dā errore ancora su quella riga modificata...

    codice:
    while ((var m = strorg.length) > 0) {
    
      var j = Math.floor(Math.random()*m);
      alert ("j="+j+"  car="+strorg.substr[j,1]);
      strrnd += strorg.substr[j,1];
      strorg = strorg.substr(0,j) + strorg.substr(j+1);
      alert ("controllo: strorg="+strorg); // da togliere dopo il debug)
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

  9. #9
    Utente di HTML.it
    Registrato dal
    Aug 2003
    Messaggi
    311
    prova a mettere le parentesi tonde invece delle quadre dove c'č substr

  10. #10
    ora l'errore č qui...

    strrnd += strorg.substr(j,1);
    [ SimplyMepis 8 ]Copyleft
    www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
    www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
    [ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.