 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andrea Guest
|
Posted: Thu Jan 27, 2005 10:52 am Post subject: Togliere gli spazi in una stringa |
|
|
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
|
Posted: Thu Jan 27, 2005 1:56 pm Post subject: Re: Togliere gli spazi in una stringa |
|
|
"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
|
Posted: Thu Jan 27, 2005 2:07 pm Post subject: Re: Togliere gli spazi in una stringa |
|
|
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
|
Posted: Thu Jan 27, 2005 3:51 pm Post subject: Re: Togliere gli spazi in una stringa |
|
|
| 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
|
Posted: Thu Jan 27, 2005 5:10 pm Post subject: Re: Togliere gli spazi in una stringa |
|
|
Veramente il metodo (di String) più indicato è trim().
|
|
| Back to top |
|
 |
Giambo Guest
|
Posted: Thu Jan 27, 2005 8:07 pm Post subject: Re: Togliere gli spazi in una stringa |
|
|
[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 |
|
 |
|
|
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
|
|