Okay, this is the first time I go out here, so carry me.
I have a name in the format of "Smith, Bob I"
and I need to switch this line to read "Bob I. Smith"
. Any ideas on how to do this?
This is one of the ways I've tried, and while it does this work, it looks pretty messy.
public static void main(String[] args) { String s = "Smith, Bob I.", r = ""; String[] names; for(int i =0; i < s.length(); i++){ if(s.indexOf(',') != -1){ if(s.charAt(i) != ',') r += s.charAt(i); } } names = r.split(" "); for(int i = 0; i < names.length; i++){ } System.out.println(names[1] +" " + names[2] + " " + names[0]); }
source share