2 suggestions:
- Use a CSV parsing library like commons-csv to tokenize the input and then re-join it with whichever character you want. CSV libraries are smart enough not to split on commas within quotes.
- Implement a finite state machine (2 states: within quotes and outside quotes) to scan the input keeping track of whether or not the current character is inside quotes. When you find a comma and you're not inside quotes, replace it.