• Post Reply Bookmark Topic Watch Topic
  • New Topic

String split and join from certain index  RSS feed

 
Peter Benda
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
string : eventNamesPathTokens="a b c"
i want to get "b c"
this is what i do
i String.join(" ", Arrays.copyOfRange(eventNamesPathTokens.split(" "), 1,eventNamesPathTokens.get.split(" ").length));
is there any easier way?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to get "b c" 

What defines the substring you want to get?  For example
Starts at third character
Starts after first space
Last two tokens in the String

Are spaces important?  What would be the desired String from: " this    sentence     ends    here"?
Is this it:  "sentence     ends    here"
 
Carey Brown
Saloon Keeper
Posts: 3312
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puter Benda wrote:string : eventNamesPathTokens="a b c"
i want to get "b c"
this is what i do
i String.join(" ", Arrays.copyOfRange(eventNamesPathTokens.split(" "), 1,eventNamesPathTokens.get.split(" ").length));
is there any easier way?

 
Peter Benda
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
Puter Benda wrote:string : eventNamesPathTokens="a b c"
i want to get "b c"
this is what i do
i String.join(" ", Arrays.copyOfRange(eventNamesPathTokens.split(" "), 1,eventNamesPathTokens.get.split(" ").length));
is there any easier way?



i want to take from second char/word until the end
 
Carey Brown
Saloon Keeper
Posts: 3312
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puter Benda wrote:
Carey Brown wrote:
Puter Benda wrote:string : eventNamesPathTokens="a b c"
i want to get "b c"
this is what i do
i String.join(" ", Arrays.copyOfRange(eventNamesPathTokens.split(" "), 1,eventNamesPathTokens.get.split(" ").length));
is there any easier way?



i want to take from second char/word until the end
So, what's the problem with what I provided?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  from second char/word until the end

Note that a space is a character.
" a b c" >> second character is a
"this  ain't it" >> second character is h, second word is ain't
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!