Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Roborock Qrevo Curv 2 Flow: ora lava con un rullo
Roborock Qrevo Curv 2 Flow: ora lava con un rullo
Qrevo Curv 2 Flow è l'ultima novità di casa Roborock per la pulizia di casa: un robot completo, forte di un sistema di lavaggio dei pavimenti basato su rullo che si estende a seguire il profilo delle pareti abbinato ad un potente motore di aspirazione con doppia spazzola laterale
Alpine A290 alla prova: un'auto bella che ti fa innamorare, con qualche limite
Alpine A290 alla prova: un'auto bella che ti fa innamorare, con qualche limite
Abbiamo guidato per diversi giorni la Alpine A290, la prima elettrica del nuovo corso della marca. Non è solo una Renault 5 sotto steroidi, ha una sua identità e vuole farsi guidare
Recensione HONOR Magic 8 Lite: lo smartphone indistruttibile e instancabile
Recensione HONOR Magic 8 Lite: lo smartphone indistruttibile e instancabile
Abbiamo provato a fondo il nuovo Magic 8 Lite di HONOR, e per farlo siamo volati fino a Marrakech , dove abbiamo testato la resistenza di questo smartphone in ogni condizione possibile ed immaginabile. Il risultato? Uno smartphone praticamente indistruttibile e con un'autonomia davvero ottima. Ma c'è molto altro da sapere su Magic 8 Lite, ve lo raccontiamo in questa recensione completa.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 22-07-2010, 09:37   #1
Giovanni Tavella
Member
 
Iscritto dal: Feb 2010
Messaggi: 31
[Java] Prendere numeri e "Sotto stringhe" da una stringa

Se ho una stringa String S="10 attaccanti, 11 palloni,13 difensori"

dove ogni "parola" o "numero"contenuto nella stringa è separata dal "numero o parola" successiva da diversi "spazi vuoti", ma so che la stringa è formata da un "numero" seguito da una "parola".

Esempio: String esempio="Gianni 18 marco 1 mario 2".

vorrei sapere se esiste qualche metodo per estrarre da una stringa , prima un
"numero" e poi "una parola" separati da uno spazio o più.


Spero di essere stato chiaro



cosi va bene secondo voi(?) :


LinkedList numeri=new LinkedList();

LinkedList parole=new LinkedList();

String Esempio="Gianni 18 marco 1 mario 2";

Scanner scanner = new Scanner(Esempio);

scanner.useDelimiter("cosa metto come delimitatore"); /cosa metto come delimitatore??

while(scanner.hasNext()) {

numeri.add(scanner.next());

parole.add(scanner.next());

}
__________________
-.-''

Ultima modifica di Giovanni Tavella : 22-07-2010 alle 11:36.
Giovanni Tavella è offline   Rispondi citando il messaggio o parte di esso
Old 22-07-2010, 09:45   #2
!fazz
Moderatore
 
L'Avatar di !fazz
 
Iscritto dal: Nov 2006
Messaggi: 22005
regex

Quote:
split

public String[] split(String regex,
int limit)

Splits this string around matches of the given regular expression.

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

The string "boo:and:foo", for example, yields the following results with these parameters:

Regex Limit Result
: 2 { "boo", "and:foo" }
: 5 { "boo", "and", "foo" }
: -2 { "boo", "and", "foo" }
o 5 { "b", "", ":and:f", "", "" }
o -2 { "b", "", ":and:f", "", "" }
o 0 { "b", "", ":and:f" }

An invocation of this method of the form str.split(regex, n) yields the same result as the expression

Pattern.compile(regex).split(str, n)

Parameters:
regex - the delimiting regular expression
limit - the result threshold, as described above
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern

__________________
"WS" (p280,cx750m,4790k+212evo,z97pro,4x8GB ddr3 1600c11,GTX760-DC2OC,MZ-7TE500, WD20EFRX)
Desktop (three hundred,650gq,3800x+nh-u14s ,x570 arous elite,2x16GB ddr4 3200c16, rx5600xt pulse P5 1TB)+NB: Lenovo p53 i7-9750H,64GB DDR4,2x1TB SSD, T1000
!fazz è offline   Rispondi citando il messaggio o parte di esso
Old 22-07-2010, 11:17   #3
Giovanni Tavella
Member
 
Iscritto dal: Feb 2010
Messaggi: 31
I no speak English

__________________
-.-''
Giovanni Tavella è offline   Rispondi citando il messaggio o parte di esso
Old 22-07-2010, 15:11   #4
!fazz
Moderatore
 
L'Avatar di !fazz
 
Iscritto dal: Nov 2006
Messaggi: 22005
Quote:
Originariamente inviato da Giovanni Tavella Guarda i messaggi
allora meglio che lo impari, almeno quello tecnico altrimenti nella programmazione non vai tanto avanti

cmq in parole povere la classe string ha il metodo split che permette di dividere una stringa in un insieme di stringhe (restituite in un array) secondo quanto definito nella regex passata come parametro

http://java.html.it/articoli/leggi/2...olari-in-java/
__________________
"WS" (p280,cx750m,4790k+212evo,z97pro,4x8GB ddr3 1600c11,GTX760-DC2OC,MZ-7TE500, WD20EFRX)
Desktop (three hundred,650gq,3800x+nh-u14s ,x570 arous elite,2x16GB ddr4 3200c16, rx5600xt pulse P5 1TB)+NB: Lenovo p53 i7-9750H,64GB DDR4,2x1TB SSD, T1000
!fazz è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Roborock Qrevo Curv 2 Flow: ora lava con un rullo Roborock Qrevo Curv 2 Flow: ora lava con un rull...
Alpine A290 alla prova: un'auto bella che ti fa innamorare, con qualche limite Alpine A290 alla prova: un'auto bella che ti fa ...
Recensione HONOR Magic 8 Lite: lo smartphone indistruttibile e instancabile Recensione HONOR Magic 8 Lite: lo smartphone ind...
Sony WF-1000X M6: le cuffie in-ear di riferimento migliorano ancora Sony WF-1000X M6: le cuffie in-ear di riferiment...
Snowflake porta l'IA dove sono i dati, anche grazie a un accordo con OpenAI Snowflake porta l'IA dove sono i dati, anche gra...
Samsung annuncia l'arrivo in Italia dei ...
Offerta lancio Pixel 10a: come ottenere ...
Google presenta Pixel 10a: poche le novi...
Caos F1 2026: 14 monoposto senza omologa...
Tesla festeggia il primo Cybercab prodot...
Desktop piccolo e potente? NZXT H2 Flow ...
Logan Paul vende la sua carta Pokemon &q...
Polestar spinge sull'acceleratore: arriv...
Nuovo record mondiale nel fotovoltaico: ...
L'ultimo baluardo cade: fine supporto pe...
'Il mondo non ha mai visto nulla di simi...
La Commissione europea mette sotto indag...
Arriva il primo computer quantistico ad ...
'Se lavori al PC sei a rischio': la prev...
Windows 11 introduce il supporto nativo ...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 16:24.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v