• Post Reply Bookmark Topic Watch Topic
  • New Topic

i cant ...... learn to use the split  RSS feed

 
Oskar Mora
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I dont know how use the metod split for extract the first word of Pilotos.txt ........
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know how use the metod split for extract the first word of Pilotos.txt ........


The split() method uses regex... so... first thing.... how comfortable are you with regular expressions?

Henry
 
Oskar Mora
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an text

1 1 12 12 234
(have on lines in a String) and i need cut 2 parts ....... the first letter or number and save on a array (Pilotos) and the other save on the other array (tiempo) ....
and i dont know how ....... I need help of these.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a good idea to read this first.
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String#split() takes whitespace as a default delimiter. So it would split
1 1 12 12 234
into "1" "1"" "12" "12" "234", if you don't provide your own delimiter.
You can use a regular expression to see whether the first token matches numbers or not. Or you can use the isXXX methods of the Character class to see whether a particular character is a letter, number, etc.
 
Oskar Mora
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:String#split() takes whitespace as a default delimiter. So it would split
1 1 12 12 234
into "1" "1"" "12" "12" "234", if you don't provide your own delimiter.
You can use a regular expression to see whether the first token matches numbers or not. Or you can use the isXXX methods of the Character class to see whether a particular character is a letter, number, etc.

i resolve it ;) . Ups split are really simple xD but i dont see the real solution ;)

Thanksssssssss
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:String#split() takes whitespace as a default delimiter. So it would split
1 1 12 12 234
into "1" "1"" "12" "12" "234", if you don't provide your own delimiter.
...


You're probably mistaking String.spilt(...) with StringTokenizer, which will tokenize a string on it's white spaces if no parameter is provided. String's split(...) method always expects a parameter.
 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String split = "abe.xyz.pqr" ;
String splitString[] = split.split("\\.") ;
for ( String sp : splitString ) {
System.out.println( sp );
}

out put is :

abe
xyz
pqr
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, Piet. Sorry for my mistake.
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You are right, Piet. Sorry for my mistake.


No problem, everybody makes them.
I must confess that I first thought I had missed some Java 1.6 enhancement! I double checked the Java 1.6 API docs of the String class before posting! ;)
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't check String, did I? I just thought it was like Scanner.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!