AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sostituire carattere in un file

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
cutoff
Guest





PostPosted: Fri Mar 24, 2006 1:12 pm    Post subject: Sostituire carattere in un file Reply with quote



Ciao,

ho un file di testo che contiene al suo interno una cosa del genere :

LONG = 04-24-26-E, LAT = 41-07-29-N, DESCR = "BARI AUTOS, UMTS e GSM",
DESCR2 = "OK vai", H_SLM = 10 BEGIN RBD "UC, VR53U2" T317 = 180

Ora dovrei sostituire il carattere virgola(,) con il carattere & ,MA SOLO se
essa è
delimitata dalle virgolette, cioè dovrei ottenere una cosa del genere :

LONG = 04-24-26-E, LAT = 41-07-29-N, DESCR = "BARI AUTOS& UMTS e GSM",
DESCR2 = "OK vai", H_SLM = 10 BEGIN RBD "UC& VR53U2" T317 = 180

Mi date un'aiuto x come potrei farlo?


Grazie

Nicola


--------------------------------
Inviato via http://arianna.libero.it/usenet/
Back to top
Vincent Vega
Guest





PostPosted: Fri Mar 24, 2006 1:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote



Gian Uberto Lauri ha scritto:

Quote:
Perché reinventare la ruota in Java quando il programma che ti serve
esiste e si chiama sed (anche per Windows)

Non si reiventa nessuna ruota, le operazioni con le espressioni regolari
esistono anche in Java.
Back to top
cutoff
Guest





PostPosted: Fri Mar 24, 2006 1:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote



Mi potreste dari un pò di codice di esempio per le regular expression che
non conosco!!

Grazie 1000 ancora


nicola


--------------------------------
Inviato via http://arianna.libero.it/usenet/
Back to top
Gian Uberto Lauri
Guest





PostPosted: Fri Mar 24, 2006 1:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Quote:
Long count = 12.19.13.2.16; tzolkin = 10 Cib; haab = 14 Cumku.
I get words from the Allmighty Great Gnus that
"c" == cutoff <cutoff (AT) libero (DOT) it> writes:

c> Mi date un'aiuto x come potrei farlo?

Perché reinventare la ruota in Java quando il programma che ti serve
esiste e si chiama sed (anche per Windows)

sed -e 's/\("[^,]*\),\([^"]*"\)/\1\&\2/' < origine > destinazione

--
/\ ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
//--\ | | \| | Integralista GNUslamico
\/ e allevatore di bug da competizione
Back to top
cutoff
Guest





PostPosted: Fri Mar 24, 2006 1:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Quote:
Perché reinventare la ruota in Java quando il programma che ti serve
esiste e si chiama sed (anche per Windows)

sed -e 's/\("[^,]*\),\([^"]*"\)/\1\&\2/' < origine > destinazione

Purtroppo io il contenuto del file l'ho all'interno in un 'array di byte
estratti da un file zippato.

In pratica devo leggere il contenuto del file zippato un certo numero di
byte x volta, e su questi agire la sostituzione, dopodiche "riscrivere" i
byte modificati di nuovo in quel file.
Spero di essermi spiegato, altrimenti posto un pò di codice.

Grazie

nicola



--------------------------------
Inviato via http://arianna.libero.it/usenet/
Back to top
Vincent Vega
Guest





PostPosted: Fri Mar 24, 2006 2:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Gian Uberto Lauri ha scritto:

Quote:
Si, ma il resto del programma lo devi riscrivere. E' quella la
reinvenzione della ruota, il riscrivere un programma che fa quello che
già fa sed!!!!

Si, ma come vedi lo scenario è già un po diverso. Il file è già uno
stream java.
Back to top
Gian Uberto Lauri
Guest





PostPosted: Fri Mar 24, 2006 2:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Quote:
"VV" == Vincent Vega <Vincent-Vega (AT) despammed (DOT) com> writes:

VV> Gian Uberto Lauri ha scritto:
Quote:
Perché reinventare la ruota in Java quando il programma che ti
serve esiste e si chiama sed (anche per Windows)

VV> Non si reiventa nessuna ruota, le operazioni con le espressioni
VV> regolari esistono anche in Java.

Si, ma il resto del programma lo devi riscrivere. E' quella la
reinvenzione della ruota, il riscrivere un programma che fa quello che
già fa sed!!!!

--
/\ ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
//--\ | | \| | Integralista GNUslamico
\/ e allevatore di bug da competizione
Back to top
Gian Uberto Lauri
Guest





PostPosted: Fri Mar 24, 2006 2:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Quote:
Long count = 12.19.13.2.16; tzolkin = 10 Cib; haab = 14 Cumku.
I get words from the Allmighty Great Gnus that
"c" == cutoff <cutoff (AT) libero (DOT) it> writes:

sed -e 's/\("[^,]*\),\([^"]*"\)/\1\&\2/' < origine > destinazione

c> Purtroppo io il contenuto del file l'ho all'interno in un 'array di
c> byte estratti da un file zippato.

c> In pratica devo leggere il contenuto del file zippato un certo
c> numero di byte x volta, e su questi agire la sostituzione,

Azz, nel post iniziale sembrava ti volessi ripulire il file.

Usando le classi che ti ha indicato Vincent poi usare la regexp
ed il replacement indicati.

regexp : \("[^,]*\),\([^"]*"\)

Se non è chiara, questa regexp è formata da due gruppi separati da una
virgola. Il primo gruppo fa il match con un " seguito da zero o più
caratteri che non sono virgola, il secondo con zero o più caratteri
che non sono " seguiti da un ".

matcher : $1&$2

$1 e $2 sono i gruppi di cui sopra.

c> dopodiche "riscrivere" i byte modificati di nuovo in quel file.

Nello stesso file zippato ???? Hmmmm....

--
/\ ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
//--\ | | \| | Integralista GNUslamico
\/ e allevatore di bug da competizione
Back to top
Gian Uberto Lauri
Guest





PostPosted: Fri Mar 24, 2006 2:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

Quote:
Long count = 12.19.13.2.16; tzolkin = 10 Cib; haab = 14 Cumku.
I get words from the Allmighty Great Gnus that
"VV" == Vincent Vega <vincent-vega (AT) despammed (DOT) com> writes:

VV> Gian Uberto Lauri ha scritto:
Quote:
Si, ma il resto del programma lo devi riscrivere. E' quella la
reinvenzione della ruota, il riscrivere un programma che fa quello
che già fa sed!!!!

VV> Si, ma come vedi lo scenario è già un po diverso. Il file è già
VV> uno stream java.

Già visto e già risposto. Ma quando uno dice:

"Ciao,

ho un file di testo che contiene al suo interno una cosa del genere :"

e poi dice che deve fare un replacement, mai più e mai poi mi invento
tutto il resto del problema che c'è intorno.

// In ogni caso il fatto che debba tornare in un file dopo la pulitura...

--
/\ ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
//--\ | | \| | Integralista GNUslamico
\/ e allevatore di bug da competizione
Back to top
Vincent Vega
Guest





PostPosted: Fri Mar 24, 2006 2:12 pm    Post subject: Re: Sostituire carattere in un file Reply with quote

cutoff ha scritto:

Quote:
Mi potreste dari un pò di codice di esempio per le regular expression che
non conosco!!

http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html
Vedi l'esempio al metodo appendReplacement().
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.