Java splitting strings?

前端 未结 4 893
北恋
北恋 2021-01-23 04:08

I\'m trying split a string when ever a \" \" occurs, for example the sentence test abc. Then move the first letter in each word from first to last. I got the moving the letter t

4条回答
  •  渐次进展
    2021-01-23 05:10

    Store your split strings in an array, then loop over the array and replace each one:

    String[] pieces = originalString.split(" ");
    for (int i = 0; i < pieces.length; i++)
        pieces[i] = pieces[i].subString(1) + pieces[i].charAt(0);
    

    By the way, this will just get you started -- it won't correctly handle cases where there's more than one space, single-letter words, or any other special cases (because you didn't say what you wanted to do). You'll have to handle those yourself.

提交回复
热议问题