Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Splitting a string to smaller strings.

 
James Palmer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i have a big string with lots of words in it and i want to find a way to split this string into separate words.This probably means that whenever the program finds a space it means that this is a new word and should make a new string for that one until it meets a space again.Particularly i want to use a tokenizer to do this.For example the string "I have a cat" should be split in 4 strings."I" "have" "a" "cat".Can anyone help?
 
john smith
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API javadoc:
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can learn more about the StringTokenizer here
 
David Peterson
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively use the split() method of String class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic