split - Java spliting strings -


I have a Java problem.

I am trying to split a string whenever "" occurs, for example the sentence test ABC then move the first letter in every word from the first to the last

< The letter had to be moved to work on the original string using pre-> string text = joppenpen.Searchput (empty, "screw in n normal text:"); Char firstLetter = text.charAt (0); Normal = text.substring (1, text.length () + 0) + first liter;

So my question is how do I split the string, then rotate the letters around each part of the cut string?

Thank you in advance

/ Code> -trranform-join does not have to be done; Can replace all in one such step.

  string text = "script general text:"; Text = text.resalely ("(\\ s *) (\\ w) (\\ w +)", "$ 1 $ 3 $ 2"); Println (text); // print "originally regains 3 groups:  
  \ 1: (s): Any alternate preceding white spot \ 2: (\ w): each" word " \ 3: (\ w +) The head part: Any tail part of each "word"  

Then, as the replacement makes the string clear and clear, you \ 2 and \ 3 .


So it should be clear that this problem with the replaceAll capturing group Best for There is a cool solution, but what is that the regex problem depends on the specification. Note that for example, the above Regex changes the text: to extt: (i.e. This colon is kept).

The following variation can be found on the white spots in \ s , and any sequence of characters of non-white space \ S Underlines the head / tail of it. It should be similar to your current split ("") -transform-join solution. Hi:

  string text = "Bob:! @ # $ + - "; Text = text.replaceAll (" (\\ s *) (\\ S) (\\ S +) "," $ 1 $ 3 $ 2 "); Println (text); // Print "Ohbs b @ $ $! - + " 

This variation switches to a sequence surrounded by a word character \ w + word boundary \ b if it This is what you need, this is the easiest, most readable solution for the job.

  string text = "abc: def! Ghi, jkl mno "; Text = text.replaceAll (" \\ b (\\ w) (\\ w +) \\ b "," $ 2 $ 1 "); Println (text); // print" BCA : FAD! See also, the CLG nm " 


Comments