0
String word = "Place AA BC CD EF AB";

Say I have a simple string word declared like that. Now I want to ignore the first word and go through the string contents excluding the first word. How would this be possible. Could I split at the first whitespace or is there some other way. Any help will be appreciated. Say there's an array called String [] list. This String word is list[i]. How would I split that to ignore the first word within that.

user181421
  • 57
  • 3
  • 11
  • Just [split the string](http://stackoverflow.com/a/3481842/6178459) and do nothing with the first part? – Arjan Jul 16 '16 at 00:33
  • Yes I would like to somehow ignore the first word while I read through the rest of the string. Reading through the string is not the issue, but how to ignore the first word is. So I was wondering if splitting the string at the first space would work. – user181421 Jul 16 '16 at 00:34
  • Read the top answer on the question that I linked. Then, forget about "how to ignore the first word", focus on "how to use the other words". :P You simply ignore the first word by not doing anything with it. – Arjan Jul 16 '16 at 00:36
  • What do you mean with "go through the `String`"? What is the desired output? Are you reading the string word by word? Do you just want a substing? Do you iterate through the rest `char` by `char`? – fabian Jul 16 '16 at 00:36
  • Arjan, can I split on an array element that is a string? – user181421 Jul 16 '16 at 00:39
  • that is not what I'm looking for that link is very basic and just shows simple splitting. – user181421 Jul 16 '16 at 00:41
  • What is so hard about simple splitting and then ignoring the first returned array element? – Jim Garrison Jul 16 '16 at 00:57
  • Alright maybe I'm complicating it more than it needs to be. But I'd like to remove the first word. – user181421 Jul 16 '16 at 01:01
  • If it's a duck, you can make it quack, whether the duck is in an array or not :) You can treat an array element that is a `String` in the same way you could treat any `String`. Either way, I must've misunderstood the question and @fabian's comment (*what is the desired output*) is spot on. I think the answer is to be found on that page about string splitting, or in swrap's answer below if you want the result to be a `String` that is "AA BC CD EF AB". – Arjan Jul 16 '16 at 01:02
  • Arjan, so when I iterate through the array elements I can just ignore the first index which will be the word "place"? Is it actually that simple? – user181421 Jul 16 '16 at 01:15
  • 1
    If you'd use `String[] parts = word.split(" ");`, `parts[0]` would be "Place", `parts[1]` would be "AA", `parts[2]` would be "BC" and so on. So yes you'd just ignore `parts[0]` and use the rest. Or, since it's still not entirely clear what it is that you actually want, you could use swrap's answer below if you want the result to be "AA BC CD EF AB". In any case, create a small program of a couple of lines that simply prints the results to the console and you'll see... – Arjan Jul 16 '16 at 01:25
  • Yes Arjan that is what I was trying to find an answer to. Thanks man. – user181421 Jul 16 '16 at 01:28
  • http://ideone.com/fvYAtc – Arjan Jul 16 '16 at 01:40

2 Answers2

2

Just split it and then remove from array content on index 0. This should remove the first splitted word in given string.

Filip Kováč
  • 499
  • 8
  • 15
2
String word = "Place AA BC CD EF AB";
word = word.substring(word.indexOf(" ")+1); //choose +1 for the next index
swrap
  • 314
  • 1
  • 3
  • 11