Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Tastiera gaming MSI GK600 TKL: switch hot-swap, display LCD e tre modalità wireless
Tastiera gaming MSI GK600 TKL: switch hot-swap, display LCD e tre modalità wireless
MSI FORGE GK600 TKL WIRELESS: switch lineari hot-swap, tripla connettività, display LCD e 5 strati di fonoassorbimento. Ottima in gaming, a 79,99 euro
DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici
DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici
DJI porta un importante aggiornamento alla sua linea di gimbal camera tascabili con Osmo Pocket 4: sensore CMOS da 1 pollice rinnovato, gamma dinamica a 14 stop, profilo colore D-Log a 10 bit, slow motion a 4K/240fps e 107 GB di archiviazione integrata. Un prodotto pensato per i creator avanzati, ma che convince anche per l'uso quotidiano
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori
Il primo headset open-back della linea INZONE arriva a 200 euro con driver derivati dalle cuffie da studio MDR-MV1 e un peso record di soli 199 grammi
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 22-07-2010, 08: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 10:36.
Giovanni Tavella è offline   Rispondi citando il messaggio o parte di esso
Old 22-07-2010, 08:45   #2
!fazz
Moderatore
 
L'Avatar di !fazz
 
Iscritto dal: Nov 2006
Messaggi: 22068
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, 10: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, 14:11   #4
!fazz
Moderatore
 
L'Avatar di !fazz
 
Iscritto dal: Nov 2006
Messaggi: 22068
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


Tastiera gaming MSI GK600 TKL: switch hot-swap, display LCD e tre modalità wireless Tastiera gaming MSI GK600 TKL: switch hot-swap, ...
DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici DJI Osmo Pocket 4: la gimbal camera tascabile cr...
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori Sony INZONE H6 Air: il primo headset open-back d...
Nutanix cambia pelle: dall’iperconvergenza alla piattaforma full stack per cloud ibrido e IA Nutanix cambia pelle: dall’iperconvergenza alla ...
Recensione Xiaomi Pad 8 Pro: potenza bruta e HyperOS 3 per sfidare la fascia alta Recensione Xiaomi Pad 8 Pro: potenza bruta e Hyp...
Una denuncia getta ombre sulle batterie ...
DJI Avata 2 Fly Smart Combo a 526€: il d...
Alla guida della nuova auto elettrica ci...
GeForce RTX 3060 12 GB a giugno di nuovo...
Apple Music sarà sponsor ufficiale di Po...
The Mandalorian & Grogu: trailer fin...
Fedeltà record: Apple blinda gli utenti,...
Volkswagen ID.3 Neo: fino a 630 km di au...
GPU-Z mette i dati personali a rischio? ...
La PS6 potrebbe essere retrocompatibile ...
Amazfit Cheetah 2 Pro arriva in Italia: ...
Duolingo ammette l'errore dopo un anno: ...
Samsung Galaxy Tab S10 Lite a 249€: il t...
Samsung Micro RGB: la rivoluzione del co...
Sempre più autonomia per gli smar...
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: 17:21.


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