Find a substring

  • 24
  • Locked
The getPartOfString method must return the substring that begins with the character after the first space and ends with the end of the word that follows the 4th space. Example: "CodeGym is the best place to learn Java." Result: "is the best place" Example: "Amigo and Diego are best friends!"
You can't complete this task, because you're not signed in.
Comments (7)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 32 , Kraków, Poland
8 March, 05:57
Hint: Most misleading in this task is "HARD" and "one star".
Jomar Tayactac
Level 2 , Winnipeg, Canada
26 May 2022, 16:17
Level 27 , Spanish Town, Jamaica
2 March 2021, 18:40
This task does not want a "word" that follows the 4th whitespace, it wants the substring that follows it. or more generally, any character(s) that is not a whitespace. "hello my name is ^&*%#" returning "my name is ^&*%#" will pass. I wasted a lot of time on this because the two approaches I came up with (one using regex the other a for loop) would have thrown it an exception if the character after the 4th space was not a word character.
Justin Smith
Level 38 , Greenfield, USA, United States
12 December 2021, 14:07
This appears to be true and CodeGym should clarify what they mean by a word, especially since there is a task in another lesson earlier that uses the regex definition of a word character and CodeGym doesn't explain that either.
Level 31
2 January 2022, 07:59
I too wasted a lot of time thinking I have to discard any punctuation characters and other non alphanumericals after the last word. CodeGym should clarify!!
Level 32 , Kraków, Poland
8 March, 05:49
When I start thinking second hours for what I forgot to prevent and go to discuss panel to find out that in this task logic is opposite :D
Level 34 , Phnom Penh, Cambogia
18 April 2020, 03:52
don't use "\\W'' can pass only (" ").