Truncate comma delimited string
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
What is the best/cleanest way you know of to take a comma delimited string, such as "A,B,C,D,E,F,G", and return only the 1st 5 amount of items in the list? So the result would be "A,B,C,D,E".
I don't want to split first and perform this operation to increase record volume. Please let me know if there is any another way to perform this operation.
Solved! Go to Solution.
- Labels:
- Parse
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I would probably just split the string and combine it unless you are dealing with extremely large data sets. My next choice would be using REGEX, which would probably be faster, but harder for many to understand. I'm no REGEX expert and I'm sure someone can come up with a more elegant example but the attached does what you want.
The pattern is just five instances of characters that don't include "," separated by commas: "([^,]*,[^,]*,[^,]*,[^,]*,[^,]*).*" -> "$1"
