Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

StringSplit Suggestion: Option to include deliminters in output


  • Please log in to reply
No replies to this topic
Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Just a late-at-night suggestion I thought of when trying to fall asleep with regards to the behavior of StringSplit. I think it would be useful to have an option to include delimiters in the output, instead of having to include in your code re-entering them. (Nevermind the hassle with multiple delimiters, though I know there is an example in the documentation (though not stringsplit's), for determining what the delimiter was in the substring when you use multiple delimiters.) A sample example regarding that would be breaking a paragraph into sentences based on the ending punctuation of a period (or exclamation mark or question mark if we go into multiple delimiters).

 

My suggestion would be to include a parameter with values L, R, and B for Left, Right, Both. Using the L option, you would include the delimiter in the preceding substring. Using that example above of a paragraph broken into sentences, you would get the ending punctuation for each string. Using the R option, those substrings would begin with the previous sentence's ending punctuation. And using Both, every substring would include a delimiter at the beginning and end (bar the first and last substrings).

 

Edit, actually, rather than a B option, how about an I (i) option? Include delimiter as their own string -- I for independent. I can't think of any particular use off the top of my head for that, but someone might. And the B option could just be represented by making that parameter LR.