[JAVA] explode zoals in PHP

Pagina: 1
Acties:

  • JSchut
  • Registratie: Februari 2002
  • Laatst online: 13-09 14:07
Ik lees een file uit per regel.
Nu heb ik op zo'n regel het volgende staan.

x;y;z

nu wil ik ze dus zoals je in PHP explode gebruikt deze regel kunnen exploden bij ;

weet iemand misschien hoe je dat doet?

PSN jschut_82 | Xbox: JSchut82


Verwijderd

Er zit vast wel een standaard functie in java maar je kan het ook zo doen:

string blaat = "x;y;aap";

char[] blaat_array = blaat.toCharArray();
string[] results;
int count = 0;

for(int i = 0; i < blaat_array.length; i++)
{
if(blaat_array[i] != ';')
{
results[count] += blaat_array[i];
}
else
{
count++;
}
}
}

uit mijn hoofdje dus kunnen typo;s etc inziutten

Verwijderd

zie net dat je array wel mot initten, je kan dus ook results een vector maken of eerst de ;'s tellen

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12-09 21:31

Janoz

Moderator Devschuur®

!litemod

De oplossing hierboven ziet er leuk uit :).. Maar je kunt unt beter de StringTokenizer gebruiken.

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Verwijderd

das dus de standaard functie :)

  • JSchut
  • Registratie: Februari 2002
  • Laatst online: 13-09 14:07
bedankt

PSN jschut_82 | Xbox: JSchut82


  • wasigh
  • Registratie: Januari 2001
  • Niet online

wasigh

wasigh.blogspot.com

Op maandag 04 maart 2002 13:27 schreef andrefoeken het volgende:
das dus de standaard functie :)
Nee is geen functie is een object met methodes :)
Pagina: 1