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 

Togliere gli spazi in una stringa

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





PostPosted: Thu Jan 27, 2005 10:52 am    Post subject: Togliere gli spazi in una stringa Reply with quote




Salve, ho bisogno di togliere degli spazi da una stringa!
Con Java 1.5 esiste un metodo xxx.replace(String a, String b), ed io posso
fare
xxx.replace(" ",""), nel pc sfortunatramente ho installato java 1.4.2, lo
stesso metodo esiste, ma è definito xxx.replace(char a, char b)

--------------------------------
Inviato via http://arianna.libero.it/usenet/
Back to top
Tommaso Torti
Guest





PostPosted: Thu Jan 27, 2005 1:56 pm    Post subject: Re: Togliere gli spazi in una stringa Reply with quote



"Andrea" <spv42 (AT) libero (DOT) it> wrote:
Quote:
Salve, ho bisogno di togliere degli spazi da una stringa!
Con Java 1.5 esiste un metodo xxx.replace(String a, String b), ed io posso
fare
xxx.replace(" ",""), nel pc sfortunatramente ho installato java 1.4.2, lo
stesso metodo esiste, ma è definito xxx.replace(char a, char b)

Salve!

Con la 1.4.2 hai a disposizione il metodo replaceAll
([url]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String[/url])
che può essere usato per il tuo scopo, come dimostra il seguente test:

public void testStringWithoutSpaces()
{
String stringWithSpace = "Qui Quo Qua";
assertEquals("QuiQuoQua", stringWithSpace.replaceAll(" ",""));
}



Back to top
Andrea
Guest





PostPosted: Thu Jan 27, 2005 2:07 pm    Post subject: Re: Togliere gli spazi in una stringa Reply with quote



Il 27 Gen 2005, 14:56, "Tommaso Torti" <totNOSPAM (AT) NOSPAMquinary (DOT) com> ha
scritto:
Quote:
"Andrea" <spv42 (AT) libero (DOT) it> wrote:
Salve, ho bisogno di togliere degli spazi da una stringa!
Con Java 1.5 esiste un metodo xxx.replace(String a, String b), ed io
posso
fare
xxx.replace(" ",""), nel pc sfortunatramente ho installato java 1.4.2,
lo
stesso metodo esiste, ma è definito xxx.replace(char a, char b)

Salve!

Con la 1.4.2 hai a disposizione il metodo replaceAll

([url]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String[/url])
che può essere usato per il tuo scopo, come dimostra il seguente test:

public void testStringWithoutSpaces()
{
String stringWithSpace = "Qui Quo Qua";
assertEquals("QuiQuoQua", stringWithSpace.replaceAll(" ",""));
}

E' vero, che idiota che sono!


Ti ringrazio tantissimo, non riuscivo più ad andare avanti!

--------------------------------
Inviato via http://arianna.libero.it/usenet/

Back to top
Tommaso Torti
Guest





PostPosted: Thu Jan 27, 2005 3:51 pm    Post subject: Re: Togliere gli spazi in una stringa Reply with quote


Quote:
E' vero, che idiota che sono!

Ti ringrazio tantissimo, non riuscivo più ad andare avanti!

Figurati, a volte capita ;-)

Tommaso Torti



Back to top
pioneer@inwind.it
Guest





PostPosted: Thu Jan 27, 2005 5:10 pm    Post subject: Re: Togliere gli spazi in una stringa Reply with quote

Veramente il metodo (di String) più indicato è trim().

Back to top
Giambo
Guest





PostPosted: Thu Jan 27, 2005 8:07 pm    Post subject: Re: Togliere gli spazi in una stringa Reply with quote

[email]pioneer (AT) inwind (DOT) it[/email] wrote:

Quote:
Veramente il metodo (di String) più indicato è trim().

Non credo sia quello che voleva lui:

Returns a copy of the string, with leading and trailing whitespace omitted.

Lui voleva eliminare tutti gli spazi dalla stringa.

--
Giambo - Occhio al filtro antispam _e_ alla whitelist !

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.