I think you mean punctuation characters. I've picked a few that you might use for this example.
String hey = 'here is some stuff. Punctuation is the thing! Yes, split on that';
String[] strings = hey.split('[,.\\!\\:\\?]');
For (String s : strings){
System.debug(s);
}
As you can see, the split expression is a regular expression. This is the reason for the escaping of these characters eg \\!
in the expression.
To be able to reconstruct the string, you could use the strings
array to replace matching strings in the source string with a token. Then when you want to reconstruct, just replace the tokens with the your phrases in the strings
array.
For example:
String hey = 'hey, there is ? a lot: of bits of, punctuation. here!!';
System.debug(hey);
String[] strings = hey.split('[,.\\!\\:\\?]');
System.debug(strings);
//replace matched strings with empty
for (String fragment : strings ){
hey = hey.replace(fragment,'__fragment__');
}
for (String fragment : strings){
hey = hey.replaceFirst('__fragment__',fragment);
}
System.debug(hey);